perf: stable Mapping hidden class in _parseMappings#70
Merged
Conversation
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
Mapping objects built by
_parseMappingswere allocated via a literal that setsource/originalLine/originalColumn/nametonull, and were then mutated to overwrite some of those nulls with numbers a few statements later. Each null→number write trips a V8 hidden-class transition, so the resulting mapping objects don't all share the same shape and downstream property reads pay polymorphic-IC costs.This PR computes every field into a local first and builds the mapping with a single literal. The mapping shape is stable from allocation onward;
eachMappingiteration (which reads all six fields per mapping) is the biggest beneficiary.Results (babel.min.js.map, three full bench-diff runs, medians)
vscode.map (scoped phases) shows the same pattern: eachMapping +10%, init −1.5%.
The tradeoff: ~2% slower init in exchange for ~10–15% faster eachMapping and ~3–5% faster generatedPositionFor. For most consumers (bundlers, source-resolvers, error reporters) the per-consumer init cost is paid once and the lookup/iteration cost is paid many times, so the net is clearly positive — but the init delta is real and worth flagging.
Test plan
yarn test— 205/205 non-TODO tests pass; 8 pre-existing TODO failures unrelatedbench-diff.sh main traceon babel, three independent runs, eachMapping wins are reproducible (+13.3%, +13.6%, +15.0%)bench-diff.sh main traceon vscode.map confirms the same pattern at scale