Files
node/test/parallel/test-source-map-section-names.js
Jacky Zhao 3db9632585 module: store source map mappings in a typed array
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>
PR-URL: https://github.com/nodejs/node/pull/66261
Reviewed-By: Chengzhong Wu <legendecas@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
2026-11-17 14:58:30 +00:00

36 lines
1.0 KiB
JavaScript

'use strict';
require('../common');
const assert = require('assert');
const { SourceMap } = require('node:module');
// Names are looked up across sections, including sections that have no names.
const sm = new SourceMap({
version: 3,
sections: [
{
offset: { line: 0, column: 0 },
map: { version: 3, sources: ['a.js'], names: ['a0', 'a1'],
mappings: 'AAAAA,CAAAC' },
},
{
offset: { line: 1, column: 0 },
map: { version: 3, sources: ['b.js'], mappings: 'AAAA' },
},
{
offset: { line: 2, column: 0 },
map: { version: 3, sources: ['c.js'], names: [], mappings: 'AAAA' },
},
{
offset: { line: 3, column: 0 },
map: { version: 3, sources: ['d.js'], names: ['d0'],
mappings: 'AAAAA' },
},
],
});
assert.strictEqual(sm.findEntry(0, 0).name, 'a0');
assert.strictEqual(sm.findEntry(0, 1).name, 'a1');
assert.strictEqual(sm.findEntry(1, 0).name, undefined);
assert.strictEqual(sm.findEntry(2, 0).name, undefined);
assert.strictEqual(sm.findEntry(3, 0).name, 'd0');