fix: improve performance in many places#209
Conversation
- readMappings: avoid Int32Array iterator protocol by indexing `currentData[0]` directly instead of destructuring - createMappingsSerializer: skip `";".repeat(1)` for the dominant consecutive-line case - splitIntoPotentialTokens: replace chained `===` comparisons with two Uint8Array lookup tables in the hot scan loops - streamChunksOfSourceMap: hoist `lines.length` and drop a redundant per-iteration bounds check; in the lines-only path the bounds check is already guaranteed by the leading guard - streamChunksOfCombinedSourceMap: coerce binary-search `r` to int32 - ConcatSource.streamChunks: only compute the remapped `nameIndex` when the chunk actually carries a source mapping https://claude.ai/code/session_013RELTj96iEXrmMSPxnwjeR
🦋 Changeset detectedLatest commit: b7b260c The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
|
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #209 +/- ##
==========================================
- Coverage 97.77% 97.72% -0.05%
==========================================
Files 25 25
Lines 1932 1938 +6
Branches 606 607 +1
==========================================
+ Hits 1889 1894 +5
- Misses 41 42 +1
Partials 2 2
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
Merging this PR will improve performance by 70.17%
|
| Benchmark | BASE |
HEAD |
Efficiency | |
|---|---|---|---|---|
| ⚡ | concat-source: streamChunks() with SourceMapSource child |
17.6 ms | 14.7 ms | +19.84% |
| ⚡ | cached-source: streamChunks() (warm) |
14.4 ms | 11.7 ms | +23.44% |
| ⚡ | helpers/readMappings: fixture (counting callback) |
1,466.8 µs | 916.4 µs | +60.07% |
| ⚡ | helpers/readMappings: fixture (noop callback) |
27.5 ms | 16.1 ms | +70.17% |
| ⚡ | prefix-source: streamChunks() with SourceMapSource child |
16.3 ms | 13.6 ms | +20.31% |
| ⚡ | realistic-source-map-pipeline: streamChunks() (columns off) |
7 ms | 6.3 ms | +10.51% |
| ⚡ | source-map-source: streamChunks() (combined inner map) |
11.7 ms | 9.9 ms | +17.36% |
| ⚡ | source-map-source: streamChunks({finalSource:true}) |
9.9 ms | 7.1 ms | +38.48% |
| ⚡ | source-map-source: streamChunks() |
14.5 ms | 11.7 ms | +23.29% |
| ⚡ | source-map-source: streamChunks({columns:false}) |
9.5 ms | 6.6 ms | +44.52% |
Comparing claude/perf-improvements-D2ZFm (b7b260c) with main (ccfbc65)
CodSpeed reports a ~19% instruction-count regression on both `helpers/splitIntoPotentialTokens` benchmarks (and ~11% on the `original-source` streamChunks benchmarks that call it) when the chained `===` comparisons are replaced with Uint8Array lookups. Restore the comparison-chain form; the other perf changes from the previous commit (readMappings, streamChunksOfSourceMap, createMappingsSerializer, ConcatSource, streamChunksOfCombinedSourceMap) are unaffected. https://claude.ai/code/session_013RELTj96iEXrmMSPxnwjeR
currentData[0]directly instead of destructuring";".repeat(1)for the dominantconsecutive-line case
===comparisons withtwo Uint8Array lookup tables in the hot scan loops
lines.lengthand drop a redundantper-iteration bounds check; in the lines-only path the bounds check
is already guaranteed by the leading guard
rto int32nameIndexwhen the chunk actually carries a source mapping
https://claude.ai/code/session_013RELTj96iEXrmMSPxnwjeR