Skip to content

v0.6.0: faster JSON output and composition, @srcmap/remapping faster than jridgewell on Vite maps

Latest

Choose a tag to compare

@BartWaardenburg BartWaardenburg released this 17 Nov 18:22
· 6 commits to main since this release
v0.6.0
9abc1f8

This 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/remapping is faster than @jridgewell/remapping on 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_json is 1.5 to 3 times faster. The JSON string writer reads 8 bytes at a time, and to_json sizes its buffer for sourcesContent. to_json is now about as fast as oxc_sourcemap.
  • remap is 1.2 to 2 times faster. remap writes 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 returns Option<&SourceMap>, so the call does not copy an upstream map:

    let composed = srcmap_remapping::remap_ref(&outer, |_source| Some(&inner));
  • SourceMap::from_json_with_options and SourceMap::from_vlq_with_options, with ParseOptions and OutOfRangeNames. A caller can accept a name index outside names, as jridgewell does. from_json stays strict.

  • RemapTree in @srcmap/remapping-wasm. It takes each map as parts: VLQ mappings as bytes, decoded segments as an Int32Array, and sourcesContent as 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, and rangeMappings as 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 LoaderContext as its second argument.
  • Sources resolve with @jridgewell/resolve-uri, so sourceRoot joins with a slash and paths normalize.
  • A name index outside names gives 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, decodedMappings and a TraceMap instance 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/remapping throws a TypeError, as jridgewell does. Before, it returned an empty map.
  • The Rust remap calls the loader for an empty source name, and it gives a sourceless segment for an empty upstream source.
  • @srcmap/remapping and @srcmap/trace-mapping have a new dependency, @jridgewell/resolve-uri.
  • ignoreList in the result of @srcmap/remapping is 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

  • FlattenMap of a sectioned map in @srcmap/trace-mapping removes duplicate sources and names.
  • allGeneratedPositionsFor returns exact column matches only.
  • @srcmap/remapping rejects some inputs that jridgewell accepts: segments with 2, 3 or 6 fields, and a names entry 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-workload records the source map work of a real Vite run and replays it.

Full Changelog: v0.5.0...v0.6.0