Conversation
robhogan
added this pull request to stack #1982
September 26, 2026 07:54
robhogan
marked this pull request as ready for review
September 28, 2026 12:13
There was a problem hiding this comment.
Copilot review overview
馃煝 Approval recommended
No unresolved review issues were identified.
Review effort: Lite
Findings: None
What changed in this PR
Improves metro-source-map lookup performance by restricting searches to the requested generated line while preserving behavior.
Changes:
- Adds per-line mapping indexes during decoding.
- Uses line-scoped binary searches.
- Adds regression tests for lookup edge cases.
| File | Description |
|---|---|
packages/鈥媘etro-source-map/鈥媠rc/鈥婥onsumer/鈥婱appingsConsumer.js |
Implements line-indexed position lookups. |
packages/鈥媘etro-source-map/鈥媠rc/鈥媉_tests__/鈥婥onsumer-test.js |
Adds coverage for unmapped leading columns and duplicate generated columns. |
馃挕 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
`MappingsConsumer#originalPositionFor` binary-searched every mapping in the map, comparing line and then column through a closure. This records the index of the first mapping on each generated line while decoding, and searches only the target line's mappings by column. Results are unchanged, including for a column before the first mapping on its line (unmapped) and for several mappings at the same generated column (the last wins). `composeSourceMaps` with a bundle map and its Hermes map is 20.5% faster than the previous diff (95% CI 20.1-21.1%) and 2.38x faster than `main` (2.37-2.39x; 1,107ms -> 878ms on our benchmark app*), with byte-identical output. Composition's memory rises by 1.2% (1.0-1.3%, +11MB*), about 9MB of which is the per-line index (1.18M generated lines in our benchmark app's bundle map). | | Time (median) | vs previous | vs `main` | Composition memory* | vs previous | vs `main` | Peak RSS | |---|---|---|---|---|---|---|---| | `main` | 2,088ms (2,082 to 2,094) | | | 1,070MB (1,070 to 1,070) | | | 1,664MB | | Previous diff | 1,107ms (1,099 to 1,111) | | -47.1% (-47.4 to -46.7) | 898MB (897 to 899) | | -15.9% (-16.1 to -15.6) | 1,492MB | | This diff | 878ms (872 to 883) | -20.5% (-21.1 to -20.1) | -58.0% (-58.1 to -57.8) | 908MB (908 to 909) | +1.2% (+1.0 to +1.3) | -15.1% (-15.2 to -15.0) | 1,502MB | ## Changelog ``` - **[Performance]**: Faster position lookups in `metro-source-map`'s `Consumer` ``` ## Test plan New tests cover a column before a line's first mapping and repeated generated columns. They pass on `main` and on this diff. ``` yarn jest packages/metro-source-map packages/metro-symbolicate yarn flow check yarn lint ``` \* Benchmark: Mattermost Mobile 2.45.0 (React Native 0.83.9, Metro 0.83.7), iOS release bundle, unminified: 7,086 sources, 52.6MB bundle, 82.4MB flat source map. Composed with its `hermesc -O -output-source-map` map (hermes-compiler 0.14.1; 10.7MB, 1.84M segments). Timings are `composeSourceMaps` alone, excluding JSON parsing, over 105 rounds on Node 22.13.1 on an M5 Pro; each round runs `main`, every diff in this stack and a memory baseline, in a shuffled order. Figures are medians with 95% bootstrap confidence intervals - for changes, of the per-round paired ratio. Composition memory is peak RSS less that of the same process parsing both maps without composing them (594MB).
This branch has not been deployed
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.
MappingsConsumer#originalPositionForbinary-searched every mapping in the map:metro/packages/metro-source-map/src/Consumer/MappingsConsumer.js
Lines 54 to 94 in b7c2055
This records the index of the first mapping on each generated line while decoding, and searches only that line. Results are unchanged, including a column before a line's first mapping (unmapped) and repeated generated columns (the last wins).
composeSourceMapsis 20.5% faster than #1979 (95% CI 20.1-21.1%) and 2.38x faster thanmain(1,107ms -> 878ms on our benchmark app), with identical output. Memory is up 1.2% (+11MB), most of it the per-line index over 1.18M generated lines.Benchmark
AI-driven.
mainmainmainChangelog
Test plan
New tests for a column before a line's first mapping and for repeated generated columns. They pass on
maintoo.Benchmark (AI-driven): Mattermost Mobile 2.45.0 (React Native 0.83.9, Metro 0.83.7), iOS release bundle, unminified: 7,086 sources, 52.6MB bundle, 82.4MB flat source map. Composed with its
hermesc -O -output-source-mapmap (hermes-compiler 0.14.1, 10.7MB, 1.84M segments). Timings arecomposeSourceMapsalone, excluding JSON parsing, over 105 rounds on Node 22.13.1 on an M5 Pro. Each round runsmain, every PR in this stack and a memory baseline, in a shuffled order. Figures are medians with 95% bootstrap confidence intervals, for changes of the per-round paired ratio. Composition memory is peak RSS less that of the same process parsing both maps without composing them (594MB).