perf(decode): inline VLQ segment parser and skip capacity pre-pass#330
Open
Boshen wants to merge 1 commit into
Open
perf(decode): inline VLQ segment parser and skip capacity pre-pass#330Boshen wants to merge 1 commit into
Boshen wants to merge 1 commit into
Conversation
Merging this PR will not alter performance
Warning Please fix the performance issues or acknowledge them on CodSpeed. Performance Changes
Tip Investigate this regression by commenting Comparing Footnotes
|
af3c7a8 to
a901059
Compare
Two micro-optimizations to `decode_mapping`: 1. Drop the upfront `,` / `;` counting pass that pre-sized the token `Vec` to an exact upper bound. Replace it with a `mapping.len() / 3` heuristic: real-world segments are 3-5 bytes, so this slightly over-allocates without paying for the extra full scan of the input. 2. Inline `parse_vlq_segment_into` into the outer match arm and use a local `local_cursor` (copied to/from the surrounding cursor at segment boundaries). With cursor state and the `nums` array visible at the function scope the optimizer can keep them in registers across iterations, and the function-call + reborrow overhead per segment is gone. `get_unchecked` is used for the `mapping[cursor]` reads — every load is preceded by an explicit length check, so the bounds checks are already provably redundant. Behavior, error variants, and the public API are unchanged.
a901059 to
eff0ff4
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.
Summary
Two micro-optimizations to `decode_mapping`:
Skip the upfront `,` / `;` counting pass. It was used to pre-size the token `Vec` to an exact upper bound; replace with a `mapping.len() / 3` heuristic. Realistic sourcemap segments are 3-5 bytes, so this slightly over-allocates without paying for an extra full scan of the input.
Inline `parse_vlq_segment_into` into the outer match arm and use a local `local_cursor` that's copied to/from the surrounding cursor at segment boundaries. With cursor state and the `nums` array visible at the function scope the optimizer can keep them in registers across iterations, and the function-call + reborrow overhead per segment is gone.
`get_unchecked` is used for the `mapping[cursor]` reads — every load is preceded by an explicit length check, so the bounds checks are already provably redundant.
Behavior, error variants, and the public API are unchanged.
Numbers (standalone vs main, no other PRs applied)
Small improvement, mostly under noise floor for the on-disk 3 KB fixtures. The win shows up best on the synthesized large fixture in #328:
Most parse savings come from #329 (borrowed deserialization); this PR is a small additional improvement that's primarily about removing redundant work.