Commit 4d32b91
committed
perf: fast-path JSON.stringify for CachedSource cache keys
CachedSource.map(), sourceAndMap() and streamChunks() key their map-entry
cache with `JSON.stringify(options)`. That call is 60-100 ns on the
common `{}` / `{columns: false}` shapes and dominates the entire method
body once the cache is warm.
Both MapOptions and the streamChunks Options type only contain boolean
fields, so we can short-circuit the stringify for the three shapes that
account for essentially all real traffic (undefined, empty object,
columns-only) using interned string constants. Any other shape still
falls through to JSON.stringify, so keys stay byte-identical to the
on-disk BufferedMaps produced by previous CachedSource versions.
Measured on the benchmark fixtures with JIT enabled (best of 5, ns/op):
before after
warmed.map({}) 79.1 4.3 (18x)
warmed.map({columns:false})139.8 9.6 (14x)
warmed.sourceAndMap({}) 89.6 9.8 (9x)
warmed.map() / undefined 10.6 6.7 (1.6x)
warmed.sourceAndMap() 12.4 7.7 (1.6x)
Full --no-opt benchmark run shows +53% on `cached-source: map()
(cached)`, +37.6% on `cached-source: sourceAndMap() (cached)`, +34.5%
on `realistic-source-map-pipeline: warm sourceAndMap()`, and
+17-21% on `replace-source: map()` / `sourceAndMap()`. 89813 tests
still pass.
https://claude.ai/code/session_01LZbaaPrnDTu6y7s4nK4cJz1 parent c5795b8 commit 4d32b91
1 file changed
Lines changed: 31 additions & 3 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
78 | 78 | | |
79 | 79 | | |
80 | 80 | | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
81 | 109 | | |
82 | 110 | | |
83 | 111 | | |
| |||
294 | 322 | | |
295 | 323 | | |
296 | 324 | | |
297 | | - | |
| 325 | + | |
298 | 326 | | |
299 | 327 | | |
300 | 328 | | |
| |||
332 | 360 | | |
333 | 361 | | |
334 | 362 | | |
335 | | - | |
| 363 | + | |
336 | 364 | | |
337 | 365 | | |
338 | 366 | | |
| |||
379 | 407 | | |
380 | 408 | | |
381 | 409 | | |
382 | | - | |
| 410 | + | |
383 | 411 | | |
384 | 412 | | |
385 | 413 | | |
| |||
0 commit comments