Repository navigation
v0.6.0: faster JSON output and composition, @srcmap/remapping faster than jridgewell on Vite maps
LatestThis release makes the Rust crates faster at JSON output and composition. @srcmap/remapping now gives the same output as @jridgewell/remapping on real Vite maps, and it is faster.
Performance
Measured by CodSpeed against v0.5.0, against oxc_sourcemap 10 on the Preact, Chart.js and PDF.js maps, and against @jridgewell/remapping 2.3.5 on four recorded Vite 8 workloads.
@srcmap/remappingis faster than@jridgewell/remappingon Vite maps. On the three larger workloads it is 1.3 to 1.7 times faster on the first pass, and 1.5 to 1.9 times faster on later passes. The wrapper now gives each map to WASM as parts, not as JSON. The fourth workload has 11 combines, which is too few to compare.to_jsonis 1.5 to 3 times faster. The JSON string writer reads 8 bytes at a time, andto_jsonsizes its buffer forsourcesContent.to_jsonis now about as fast asoxc_sourcemap.remapis 1.2 to 2 times faster.remapwrites its result in the final layout, with no copy of the mappings and the strings. A trace keeps a cursor at its last hit.- A lookup between two segments is up to 1.5 times faster on the Chart.js map. The search has no early exit, so each step is one compare and one conditional move.
- The generator writes JSON faster too. It uses the same string writer.
What is not faster than the alternatives: in Node.js, @jridgewell/trace-mapping still parses faster and does a single lookup faster than the WASM and NAPI packages. Source map work is a small share of a Vite run (0.1% to 2.5% of the wall time in the four workloads), so the remapping gain does not make a build visibly faster. remap still takes about twice as long as compose in oxc_sourcemap, because it applies the jridgewell rules for each segment.
New API
-
srcmap_remapping::remap_ref. The loader returnsOption<&SourceMap>, so the call does not copy an upstream map:let composed = srcmap_remapping::remap_ref(&outer, |_source| Some(&inner));
-
SourceMap::from_json_with_optionsandSourceMap::from_vlq_with_options, withParseOptionsandOutOfRangeNames. A caller can accept a name index outsidenames, as jridgewell does.from_jsonstays strict. -
RemapTreein@srcmap/remapping-wasm. It takes each map as parts: VLQ mappings as bytes, decoded segments as anInt32Array, andsourcesContentas tokens that stay in JS. -
srcmap_codec::json_quote_into. It appends a string to a buffer as a JSON string.
Bug fixes
@srcmap/remapping now matches @jridgewell/remapping 2.3.5 on four recorded Vite 8 workloads (a Vitest run of vue-core and of element-plus, and a client and an SSR dev crawl of element-plus).
- A decoded map without
version, andrangeMappingsas an array, no longer fail. Vite passes both. - A segment that traces to a generated-only upstream segment gives a sourceless segment. Before, later columns on the line mapped to the previous original position. This fix is also in the Rust
remap. - On an exact column match, the trace takes the first upstream segment at that column. This fix is also in the Rust
remap. - The loader runs for each source by source index, depth first, and it gets a
LoaderContextas its second argument. - Sources resolve with
@jridgewell/resolve-uri, sosourceRootjoins with a slash and paths normalize. - A name index outside
namesgives a segment without a name. Before, the remap threw an error. - An error from the loader, and an upstream map that does not parse, now throw. Before, the remap dropped the upstream map and gave a wrong result.
excludeContent,decodedMappingsand aTraceMapinstance as input now work.
@srcmap/trace-mapping now resolves sources exactly like @jridgewell/trace-mapping 0.3.31. generatedPositionFor and allGeneratedPositionsFor find the source index the same way.
Behavior changes
remapping([], loader)in@srcmap/remappingthrows aTypeError, as jridgewell does. Before, it returned an empty map.- The Rust
remapcalls the loader for an empty source name, and it gives a sourceless segment for an empty upstream source. @srcmap/remappingand@srcmap/trace-mappinghave a new dependency,@jridgewell/resolve-uri.ignoreListin the result of@srcmap/remappingis always an array, as in jridgewell. Before, it was missing when no source was ignored.- A loader that returns a map for every source, its own output included, now overflows the stack, as in jridgewell. Before, the remap stopped after one level.
Known differences from jridgewell
FlattenMapof a sectioned map in@srcmap/trace-mappingremoves duplicate sources and names.allGeneratedPositionsForreturns exact column matches only.@srcmap/remappingrejects some inputs that jridgewell accepts: segments with 2, 3 or 6 fields, and anamesentry that is not a string.
Documentation
- The README describes srcmap as a source map toolkit, and it no longer calls the packages faster than the jridgewell packages. It states which side won each benchmark.
- The roadmap lists the planned work in order of priority.
benchmarks/vite-workloadrecords the source map work of a real Vite run and replays it.
Full Changelog: v0.5.0...v0.6.0