a collection of lightweight TypeScript packages for AT Protocol, the protocol powering Bluesky
atproto bluesky typescript npm
101
fork

Configure Feed

Select the types of activity you want to include in your feed.

chore(bluesky): new validation benchmarks

Mary 906e3ef8 fcac36fd

+295 -212
+295 -212
packages/definitions/bluesky/lib/lexicons.bench.ts
··· 1 + // realistic validation benchmark using post shapes sampled from the Bluesky firehose 2 + // distribution (20k sample from Jetstream, 2026-03-18): 3 + // reply: 32.5% | plain-text: 22.5% | external+link: 6.7% | images: 6.7% 4 + // external: 6.2% | quote: 3.7% | images+tags: 2.4% | video: 0.7% 5 + // recordWithMedia: 0.4% | external+labels: 0.1% 6 + 1 7 import { is } from '@atcute/lexicons'; 2 8 3 9 import * as atproto from '@atproto/api'; ··· 5 11 6 12 import * as atcute from './lexicons/index.ts'; 7 13 8 - summary(() => { 9 - bench('atcute', function* () { 10 - yield { 11 - [0]() { 12 - return { 13 - $type: 'app.bsky.feed.post', 14 - createdAt: '2024-01-16T02:11:28.664Z', 15 - embed: { 16 - $type: 'app.bsky.embed.images', 17 - images: [ 18 - { 19 - alt: 'Kit sleeping on me', 20 - aspectRatio: { 21 - height: 2000, 22 - width: 1500, 23 - }, 24 - image: { 25 - $type: 'blob', 26 - ref: { 27 - $link: 'bafkreieg74vbe3b5xyro3mcflzm2mb5yf525myeu2bgcif35kopii4eh5m', 28 - }, 29 - mimeType: 'image/jpeg', 30 - size: 806879, 31 - }, 32 - }, 33 - ], 14 + function pair(record: object) { 15 + summary(() => { 16 + bench('atcute', function* () { 17 + yield { 18 + [0]() { 19 + return structuredClone(record); 20 + }, 21 + bench(r: any) { 22 + return do_not_optimize(is(atcute.AppBskyFeedPost.mainSchema, r)); 23 + }, 24 + }; 25 + }); 26 + 27 + bench('atproto', function* () { 28 + yield { 29 + [0]() { 30 + return atproto.jsonToLex(structuredClone(record)); 31 + }, 32 + bench(r: any) { 33 + return do_not_optimize(atproto.AppBskyFeedPost.validateRecord(r)); 34 + }, 35 + }; 36 + }); 37 + }); 38 + } 39 + 40 + // #region plain text (en) — 22.5% of firehose 41 + pair({ 42 + $type: 'app.bsky.feed.post', 43 + createdAt: '2026-03-18T10:30:17.175Z', 44 + langs: ['en'], 45 + text: "The five constipated men in the Bible? Cain - He wasn't Abel.\nKing David - Heaven and Earth couldn't move him.\nKing Solomon - He sat on the throne for 40 years.\nMoses - He took two tablets and went up on the mountain.\nAnd Noah - He spent 40 days and 40 nights in the Ark, and passed nothing but water", 46 + }); 47 + // #endregion 48 + 49 + // #region plain text (ja) — CJK grapheme counting, ~19% of posts 50 + pair({ 51 + $type: 'app.bsky.feed.post', 52 + createdAt: '2026-03-18T10:30:16.385Z', 53 + langs: ['ja'], 54 + text: 'マンゴーかき氷が食べたい。おいしいパイナップルケーキも買いたい。各自一つ火鍋が与えられるらしい火鍋も行きたい。麺線も食べたいです。', 55 + }); 56 + // #endregion 57 + 58 + // #region reply (en) — 32.5% of firehose 59 + pair({ 60 + $type: 'app.bsky.feed.post', 61 + createdAt: '2026-03-18T10:30:16.850Z', 62 + langs: ['en'], 63 + reply: { 64 + parent: { 65 + cid: 'bafyreieh67kdw2s5kgc2beiv7rgcf6yaryagmvez2q5qc2kzkweprietvm', 66 + uri: 'at://did:plc:6tmzbiftwxfgnxz6b5t2ylsh/app.bsky.feed.post/3mhbkounjys2m', 67 + }, 68 + root: { 69 + cid: 'bafyreieh67kdw2s5kgc2beiv7rgcf6yaryagmvez2q5qc2kzkweprietvm', 70 + uri: 'at://did:plc:6tmzbiftwxfgnxz6b5t2ylsh/app.bsky.feed.post/3mhbkounjys2m', 71 + }, 72 + }, 73 + text: "I would've had a breakdown after the first thing, so I can already tell you're stronger than I.", 74 + }); 75 + // #endregion 76 + 77 + // #region images embed — 6.7% 78 + pair({ 79 + $type: 'app.bsky.feed.post', 80 + createdAt: '2026-03-18T10:30:10.415Z', 81 + embed: { 82 + $type: 'app.bsky.embed.images', 83 + images: [ 84 + { 85 + alt: '', 86 + aspectRatio: { 87 + height: 2000, 88 + width: 1500, 89 + }, 90 + image: { 91 + $type: 'blob', 92 + ref: { 93 + $link: 'bafkreibjfybaa44yecbited3s6i3swbvh4eebh2z7n3mtwyw3r3lykyjwe', 34 94 }, 35 - langs: ['en'], 36 - reply: { 37 - parent: { 38 - cid: 'bafyreiefj6k42eyvufxz7ux3i2nyzefgpjmavapto7zlcrfhzspe3eijxu', 39 - uri: 'at://did:plc:34d6gxlllrndltpas55xfedz/app.bsky.feed.post/3kj2ujyplal2i', 40 - }, 41 - root: { 42 - cid: 'bafyreihzdxsclc45we52wdy2ui7er7b6rxgh36vpoy6ecnegkujwk6yj5m', 43 - uri: 'at://did:plc:ragtjsm2j2vknwkz3zp4oxrd/app.bsky.feed.post/3kj2uf2sole2u', 44 - }, 45 - }, 46 - text: 'angel mode', 47 - }; 95 + mimeType: 'image/jpeg', 96 + size: 918219, 97 + }, 48 98 }, 49 - bench(record: any) { 50 - return do_not_optimize(is(atcute.AppBskyFeedPost.mainSchema, record)); 99 + ], 100 + }, 101 + langs: ['en'], 102 + text: 'peak doodle', 103 + }); 104 + // #endregion 105 + 106 + // #region external link + link facet — 6.7% 107 + pair({ 108 + $type: 'app.bsky.feed.post', 109 + createdAt: '2026-03-18T10:30:15.152Z', 110 + embed: { 111 + $type: 'app.bsky.embed.external', 112 + external: { 113 + description: '', 114 + thumb: { 115 + $type: 'blob', 116 + ref: { 117 + $link: 'bafkreiaax6qmoecxx2h5uh6fhlqi2ejhyandzsozds7s6owa3rqqvvxkgq', 118 + }, 119 + mimeType: 'image/jpeg', 120 + size: 30903, 51 121 }, 52 - }; 53 - }); 122 + title: 'paradise 1997', 123 + uri: 'https://open.spotify.com/track/5tyGDQeYTbqxLHsuAvWvcF?si=0GK1IDV5SHqGWhEcrjJdDg', 124 + }, 125 + }, 126 + facets: [ 127 + { 128 + features: [ 129 + { 130 + $type: 'app.bsky.richtext.facet#link', 131 + uri: 'https://open.spotify.com/track/5tyGDQeYTbqxLHsuAvWvcF?si=0GK1IDV5SHqGWhEcrjJdDg', 132 + }, 133 + ], 134 + index: { 135 + byteEnd: 37, 136 + byteStart: 5, 137 + }, 138 + }, 139 + ], 140 + langs: ['en'], 141 + text: 'mood\nopen.spotify.com/track/5tyGDQ...', 142 + }); 143 + // #endregion 144 + 145 + // #region quote post (embed.record) — 3.7% 146 + pair({ 147 + $type: 'app.bsky.feed.post', 148 + createdAt: '2026-03-18T10:30:16.953Z', 149 + embed: { 150 + $type: 'app.bsky.embed.record', 151 + record: { 152 + cid: 'bafyreiheczsalzhd36m64swmbsyjmsfxo7xyfxg3gayo4auawejt7hdklq', 153 + uri: 'at://did:plc:jqxoz37667iqtse4cbv2pge3/app.bsky.feed.post/3mhbf3vrsi22g', 154 + }, 155 + }, 156 + langs: ['en'], 157 + text: '"Well, I rode through the desert on a horse with no name..."', 158 + }); 159 + // #endregion 54 160 55 - bench('atproto', function* () { 56 - yield { 57 - [0]() { 58 - return atproto.jsonToLex({ 59 - $type: 'app.bsky.feed.post', 60 - createdAt: '2024-01-16T02:11:28.664Z', 61 - embed: { 62 - $type: 'app.bsky.embed.images', 63 - images: [ 64 - { 65 - alt: 'Kit sleeping on me', 66 - aspectRatio: { 67 - height: 2000, 68 - width: 1500, 69 - }, 70 - image: { 71 - $type: 'blob', 72 - ref: { 73 - $link: 'bafkreieg74vbe3b5xyro3mcflzm2mb5yf525myeu2bgcif35kopii4eh5m', 74 - }, 75 - mimeType: 'image/jpeg', 76 - size: 806879, 77 - }, 78 - }, 79 - ], 161 + // #region images + tag facets — 2.4% 162 + pair({ 163 + $type: 'app.bsky.feed.post', 164 + createdAt: '2026-03-18T10:30:17.690Z', 165 + embed: { 166 + $type: 'app.bsky.embed.images', 167 + images: [ 168 + { 169 + alt: '', 170 + aspectRatio: { 171 + height: 1610, 172 + width: 2000, 173 + }, 174 + image: { 175 + $type: 'blob', 176 + ref: { 177 + $link: 'bafkreiabwucd3gnplugjzgunc7g3owz5t2dufzkfj7vwig2xhh77mdcl5m', 80 178 }, 81 - langs: ['en'], 82 - reply: { 83 - parent: { 84 - cid: 'bafyreiefj6k42eyvufxz7ux3i2nyzefgpjmavapto7zlcrfhzspe3eijxu', 85 - uri: 'at://did:plc:34d6gxlllrndltpas55xfedz/app.bsky.feed.post/3kj2ujyplal2i', 86 - }, 87 - root: { 88 - cid: 'bafyreihzdxsclc45we52wdy2ui7er7b6rxgh36vpoy6ecnegkujwk6yj5m', 89 - uri: 'at://did:plc:ragtjsm2j2vknwkz3zp4oxrd/app.bsky.feed.post/3kj2uf2sole2u', 90 - }, 91 - }, 92 - text: 'angel mode', 93 - }); 179 + mimeType: 'image/jpeg', 180 + size: 424839, 181 + }, 182 + }, 183 + ], 184 + }, 185 + facets: [ 186 + { 187 + features: [ 188 + { 189 + $type: 'app.bsky.richtext.facet#tag', 190 + tag: '叢雲掲示板', 191 + }, 192 + ], 193 + index: { 194 + byteEnd: 16, 195 + byteStart: 0, 94 196 }, 95 - bench(record: any) { 96 - return do_not_optimize(atproto.AppBskyFeedPost.validateRecord(record)); 197 + }, 198 + ], 199 + langs: ['ja'], 200 + text: '#叢雲掲示板\nがう', 201 + }); 202 + // #endregion 203 + 204 + // #region video embed — 0.7% 205 + pair({ 206 + $type: 'app.bsky.feed.post', 207 + createdAt: '2026-03-18T10:30:19.713Z', 208 + embed: { 209 + $type: 'app.bsky.embed.video', 210 + aspectRatio: { 211 + height: 2340, 212 + width: 1080, 213 + }, 214 + presentation: 'default', 215 + video: { 216 + $type: 'blob', 217 + ref: { 218 + $link: 'bafkreigrbgdmc6jlkpnarpgxm5cdnswroqgm6rcsfan7w2sdhpcgin4qd4', 97 219 }, 98 - }; 99 - }); 220 + mimeType: 'video/mp4', 221 + size: 446877, 222 + }, 223 + }, 224 + langs: ['en'], 225 + text: 'I was looking for the "SNOP" panel in Homestuck and it took me to the revamped mspa site and oh my god...\n\nTHE HAMBURGER MENU ON MOBILE IS A SHITTY JPEG OF A HAMBURGER.', 100 226 }); 227 + // #endregion 101 228 102 - summary(() => { 103 - bench('atcute', function* () { 104 - yield { 105 - [0]() { 106 - return { 107 - $type: 'app.bsky.feed.post', 108 - createdAt: '2025-05-13T21:16:55.043Z', 109 - embed: { 110 - $type: 'app.bsky.embed.images', 111 - images: [ 112 - { 113 - alt: 'As explained below, Columbia University has been advised by immigration authorities that YUNSEO CHUNG is now present in the United States and that RANJANI SRINIVASAN was a removable alien and YUNSEO CHUNG is a removable\nalien. Despite this knowledge, Columbia University has refused, and continues to refuse, to permit immigration officers to locate and arrest RANJANI SRINIVASAN and YUNSEO CHUNG at their student housing and were and are thus concealing, harboring, or shielding from detection removable aliens, RANJANI SRINIVASAN and YUNSEO CHUNG, or are\nconspiring to do so.', 114 - aspectRatio: { 115 - height: 658, 116 - width: 1382, 117 - }, 118 - image: { 119 - $type: 'blob', 120 - ref: { 121 - $link: 'bafkreievlpk5ra3mcdhcll3dkxnet5cncj4wmo6ofg75tee3wbynfm6dfq', 122 - }, 123 - mimeType: 'image/jpeg', 124 - size: 406921, 125 - }, 126 - }, 127 - ], 229 + // #region record with media — 0.4%, most complex embed type 230 + pair({ 231 + $type: 'app.bsky.feed.post', 232 + createdAt: '2026-03-18T10:30:54.585Z', 233 + embed: { 234 + $type: 'app.bsky.embed.recordWithMedia', 235 + media: { 236 + $type: 'app.bsky.embed.images', 237 + images: [ 238 + { 239 + alt: '', 240 + aspectRatio: { 241 + height: 1000, 242 + width: 1000, 128 243 }, 129 - facets: [ 130 - { 131 - features: [ 132 - { 133 - $type: 'app.bsky.richtext.facet#link', 134 - uri: 'https://storage.courtlistener.com/recap/gov.uscourts.nysd.639187/gov.uscourts.nysd.639187.49.0.pdf#page=2.00', 135 - }, 136 - ], 137 - index: { 138 - byteEnd: 305, 139 - byteStart: 264, 140 - }, 244 + image: { 245 + $type: 'blob', 246 + ref: { 247 + $link: 'bafkreidxsvr467n65lox5btrv3ysnxkzmehgbzogqk46ho6sw67apuauyu', 141 248 }, 142 - ], 143 - langs: ['en'], 144 - text: 'NEW: ICE persuaded a magistrate judge that Columbia was violating 8 USC § 1324 by "harboring aliens" — i.e., students Yunseo Chung and Ranjani Srinivasan — by refusing to invite ICE onto its private campus to capture them, per the newly unsealed application. storage.courtlistener.com/recap/gov.us...', 145 - }; 146 - }, 147 - bench(record: any) { 148 - return do_not_optimize(is(atcute.AppBskyFeedPost.mainSchema, record)); 149 - }, 150 - }; 151 - }); 152 - 153 - bench('atproto', function* () { 154 - yield { 155 - [0]() { 156 - return atproto.jsonToLex({ 157 - $type: 'app.bsky.feed.post', 158 - createdAt: '2025-05-13T21:16:55.043Z', 159 - embed: { 160 - $type: 'app.bsky.embed.images', 161 - images: [ 162 - { 163 - alt: 'As explained below, Columbia University has been advised by immigration authorities that YUNSEO CHUNG is now present in the United States and that RANJANI SRINIVASAN was a removable alien and YUNSEO CHUNG is a removable\nalien. Despite this knowledge, Columbia University has refused, and continues to refuse, to permit immigration officers to locate and arrest RANJANI SRINIVASAN and YUNSEO CHUNG at their student housing and were and are thus concealing, harboring, or shielding from detection removable aliens, RANJANI SRINIVASAN and YUNSEO CHUNG, or are\nconspiring to do so.', 164 - aspectRatio: { 165 - height: 658, 166 - width: 1382, 167 - }, 168 - image: { 169 - $type: 'blob', 170 - ref: { 171 - $link: 'bafkreievlpk5ra3mcdhcll3dkxnet5cncj4wmo6ofg75tee3wbynfm6dfq', 172 - }, 173 - mimeType: 'image/jpeg', 174 - size: 406921, 175 - }, 176 - }, 177 - ], 249 + mimeType: 'image/jpeg', 250 + size: 185316, 251 + }, 252 + }, 253 + { 254 + alt: '', 255 + aspectRatio: { 256 + height: 1920, 257 + width: 1080, 178 258 }, 179 - facets: [ 180 - { 181 - features: [ 182 - { 183 - $type: 'app.bsky.richtext.facet#link', 184 - uri: 'https://storage.courtlistener.com/recap/gov.uscourts.nysd.639187/gov.uscourts.nysd.639187.49.0.pdf#page=2.00', 185 - }, 186 - ], 187 - index: { 188 - byteEnd: 305, 189 - byteStart: 264, 190 - }, 259 + image: { 260 + $type: 'blob', 261 + ref: { 262 + $link: 'bafkreic6romobsny3aavmkgqysqbt54z27htkwtp4rdjjyszneasstxjz4', 191 263 }, 192 - ], 193 - langs: ['en'], 194 - text: 'NEW: ICE persuaded a magistrate judge that Columbia was violating 8 USC § 1324 by "harboring aliens" — i.e., students Yunseo Chung and Ranjani Srinivasan — by refusing to invite ICE onto its private campus to capture them, per the newly unsealed application. storage.courtlistener.com/recap/gov.us...', 195 - }); 264 + mimeType: 'image/jpeg', 265 + size: 947838, 266 + }, 267 + }, 268 + ], 269 + }, 270 + record: { 271 + $type: 'app.bsky.embed.record', 272 + record: { 273 + cid: 'bafyreigtx64bk7d63alydtfbpt5m3ebhh2cpybvncozxawuvvyso37aqfu', 274 + uri: 'at://did:plc:vvn4cqb6l3mc4dg7n2lh6xb4/app.bsky.feed.post/3mhd2mqhahc2h', 196 275 }, 197 - bench(record: any) { 198 - return do_not_optimize(atproto.AppBskyFeedPost.validateRecord(record)); 199 - }, 200 - }; 201 - }); 276 + }, 277 + }, 278 + langs: ['es'], 279 + text: 'Icon vs user!!', 202 280 }); 203 - 204 - summary(() => { 205 - bench('atcute', function* () { 206 - yield { 207 - [0]() { 208 - const record: atcute.AppBskyFeedPost.Main = { 209 - $type: 'app.bsky.feed.post', 210 - createdAt: new Date().toISOString(), 211 - text: '👨‍👩‍👧‍👦'.repeat(90), 212 - }; 281 + // #endregion 213 282 214 - return record; 283 + // #region external + self-labels (bot/feed posts) — 0.1% 284 + pair({ 285 + $type: 'app.bsky.feed.post', 286 + createdAt: '2026-03-18T09:58:36.000000Z', 287 + embed: { 288 + $type: 'app.bsky.embed.external', 289 + external: { 290 + description: 291 + "Former reality TV star Jessie Holmes cruised to a repeat victory in the Iditarod, the roughly 1,000-mile sled dog race in Alaska", 292 + thumb: { 293 + $type: 'blob', 294 + ref: { 295 + $link: 'bafkreica5staxokii3db6xkxrzpnadh6rfptxexca3gtjqbvwoby5ghpsu', 296 + }, 297 + mimeType: 'image/jpeg', 298 + size: 235971, 215 299 }, 216 - bench(record: any) { 217 - return do_not_optimize(is(atcute.AppBskyFeedPost.mainSchema, record)); 218 - }, 219 - }; 220 - }); 300 + title: 'Former reality TV star Jessie Holmes repeats as champion of the grueling Iditarod sled dog race', 301 + uri: 'https://www.independent.co.uk/news/alaska-bering-sea-national-geographic-anchorage-willow-b2940836.html', 302 + }, 303 + }, 304 + facets: [], 305 + labels: { 306 + $type: 'com.atproto.label.defs#selfLabels', 307 + values: [], 308 + }, 309 + langs: [], 310 + tags: [], 311 + text: "Former reality TV star Jessie Holmes repeats as champion of the grueling Iditarod sled dog race\n\nFormer reality TV star Jessie Holmes cruised to a repeat victory in the Iditarod, the roughly 1,000-mile sled dog race in Alaska\n", 312 + }); 313 + // #endregion 221 314 222 - bench('atproto', function* () { 223 - yield { 224 - [0]() { 225 - const record: atcute.AppBskyFeedPost.Main = { 226 - $type: 'app.bsky.feed.post', 227 - createdAt: new Date().toISOString(), 228 - text: '👨‍👩‍👧‍👦'.repeat(90), 229 - }; 230 - 231 - return atproto.jsonToLex(record); 232 - }, 233 - bench(record: any) { 234 - return do_not_optimize(atproto.AppBskyFeedPost.validateRecord(record)); 235 - }, 236 - }; 237 - }); 315 + // #region grapheme stress test — family emoji at max grapheme limit 316 + pair({ 317 + $type: 'app.bsky.feed.post', 318 + createdAt: '2026-03-18T00:00:00.000Z', 319 + text: '\u{1F468}\u{200D}\u{1F469}\u{200D}\u{1F467}\u{200D}\u{1F466}'.repeat(90), 238 320 }); 321 + // #endregion 239 322 240 323 await run();