Skip to content

sourcemaps: store source map mappings in a typed array - #66261

Open
jackyzha0 wants to merge 1 commit into
nodejs:mainfrom
jackyzha0:sourcemap-typed-mappings
Open

jackyzha0 wants to merge 1 commit into
nodejs:mainfrom
jackyzha0:sourcemap-typed-mappings

Conversation

@jackyzha0

Copy link
Copy Markdown
Contributor

Why

SourceMap kept one six-element array per mapping segment. Bundled applications have millions of segments, and with --enable-source-maps these arrays live for the life of the process. From our prod application, a 63 MB source map with 2.9 million segments retained about 290 MiB of heap.

What changed

  • Store the segments in a single Int32Array, six fields per segment, and resolve source URLs and names through per-map tables.
  • Segments are counted before parsing so storage is allocated once, and sorting is skipped when the mappings are already in order.
    • The public API and the objects returned by findEntry() and findOrigin() are unchanged.

Disclaimer: this PR was written with the help of Opus 5.5 but I have personally read, reviewed, and validated the changes.

SourceMap kept one six-element array per mapping segment. Bundled
applications have millions of segments, and with --enable-source-maps
a parsed map lives for the life of the process: a 63 MB source map with
2.9 million segments retained about 290 MiB of heap.

Store the segments in a single Int32Array, six fields per segment, and
resolve source URLs and names through per-map tables. Segments are
counted before parsing so storage is allocated once, and sorting is
skipped when the mappings are already in order. The public API and the
objects returned by findEntry() and findOrigin() are unchanged.

Signed-off-by: Jacky Zhao <j.zhao2k19@gmail.com>
@nodejs-github-bot

Copy link
Copy Markdown
Collaborator

Review requested:

  • @nodejs/test_runner

@nodejs-github-bot nodejs-github-bot added needs-ci PRs that need a full CI run. source maps Issues and PRs related to source map support. test_runner Issues and PRs related to the test runner subsystem. labels Sep 24, 2026
@codecov

codecov Bot commented Sep 24, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 98.93048% with 2 lines in your changes missing coverage. Please review.
✅ Project coverage is 90.29%. Comparing base (e7d8ab5) to head (2cb056f).
⚠️ Report is 2 commits behind head on main.

Files with missing lines Patch % Lines
lib/internal/source_map/source_map.js 99.45% 1 Missing ⚠️
lib/internal/test_runner/coverage.js 50.00% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main   #66261      +/-   ##
==========================================
- Coverage   90.30%   90.29%   -0.01%     
==========================================
  Files         789      789              
  Lines      272880   273012     +132     
  Branches    52110    52135      +25     
==========================================
+ Hits       246418   246515      +97     
- Misses      16912    16963      +51     
+ Partials     9550     9534      -16     
Files with missing lines Coverage Δ
lib/internal/source_map/source_map.js 99.61% <99.45%> (+0.12%) ⬆️
lib/internal/test_runner/coverage.js 59.81% <50.00%> (ø)

... and 36 files with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

needs-ci PRs that need a full CI run. source maps Issues and PRs related to source map support. test_runner Issues and PRs related to the test runner subsystem.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants