perf(source-map): reuse resolved segments in range queries - #108
Merged
Merged
Conversation
luojiyin1987
force-pushed
the
perf/reuse-resolved-segments
branch
2 times, most recently
from
September 7, 2026 03:29
282b859 to
bd70520
Compare
resolveSegmentRange() already binary-searches for start and end segment indices, then calls sourceOffsetAt() which re-does the same search via findSegmentAt(). Inline the offset calculation to drop 2 redundant binary searches per range query. Remove the now-dead sourceOffsetAt() function.
luojiyin1987
force-pushed
the
perf/reuse-resolved-segments
branch
from
September 7, 2026 03:34
bd70520 to
0ff0da0
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
Reuse the already-resolved segment indices in
resolveSegmentRange()instead of callingsourceOffsetAt()(which re-does the same binary search viafindSegmentAt()).Why
A non-empty range query performed 4 x O(log segments) binary searches:
findSegmentIndexAt(segments, valueStart)— keptfindSegmentIndexAt(segments, valueEnd - 1)— keptsourceOffsetAt()->findSegmentAt(segments, valueStart)— removedsourceOffsetAt()->findSegmentAt(segments, valueEnd - 1)— removedSteps 3-4 are now inlined using the already-resolved indices from steps 1-2.
Changes
resolveSegmentRange(): inline offset calculation from the resolved segment indices; removevalueLengthfrom destructuring (no longer needed).sourceOffsetAt(): removed (zero callers after inline).bench-source-map.mjs: addrandom range queries(10k random range queries per size), renamerandom queriestorandom single-unit queries, increasequery full value rangefrom 1k to 10k iterations, switch query patterns fromtime()totimeMedian()for stable A/B comparison.Benchmark (A/B, 3-sample median)
random single-unit queriesconsistently shows 31-65% speedup across sizes.random range queriesis noisier because the optimization only eliminates the second pair of searches — the first pair (already present before) dominates the variance.Verification