-
perf: stream potential tokens in OriginalSource instead of materialising an array (by @alexander-akait in #246)
OriginalSource.streamChunks(and thereforemap()/sourceAndMap()) previously built the fullsplitIntoPotentialTokensarray of substrings and then iterated it — even thoughmap()andsourceAndMap()run withfinalSource: trueand discard every chunk substring. The scan is now streamed by offset, so chunk substrings are only allocated when actually emitted. This removes the intermediate array and, on the dominant final-source paths, all per-token slices:map()/sourceAndMap()allocate ~38–46% less memory and run ~15–40% faster. -
Reduce allocations and CPU in
map()/sourceAndMap(): mappings are serialized into a reused byte buffer instead of per-mapping strings,ReplaceSourceverifies original content through a line-offset index instead of splitting sources into line arrays, andReplaceSource.streamChunksemits position-only chunks and returns the final source directly whenfinalSourceis requested. (by @alexander-akait in #251) -
Skip sorting ReplaceSource replacements when they were added in order. (by @alexander-akait in #249)
-
perf: use lookup table in splitIntoPotentialTokens for faster character classification (by @xiaoxiaojx in #240)
Replace multi-comparison chains (4 comparisons in phase 1, 6 in phase 2) with a single Uint8Array bitmask lookup per character. This reduces per-character branching overhead, yielding ~7% improvement on typical source and ~21% on large sources.
- Add
clearCache(options?, visited?)method toSourcethat recursively releases cached data (CachedSourcecached maps/buffers/strings,SourceMapSourceparsed/serialized map caches, and dual-buffer caches in leaf sources). Lets consumers like webpack'sSourceMapDevToolPluginreclaim memory between chunks rather than accumulating per-task source map data across an entire build. Options:maps(defaulttrue) drops cached source maps;source(defaulttrue) drops cached source/buffer copies — passfalseto keep source available for downstream plugins;parsedMap(defaultfalse) additionally drops the parsed object form onSourceMapSourceinstances when a buffer or string form survives (the combination{ maps: true, source: false, parsedMap: true }matches theSourceMapDevToolPlugincall shape in webpack/webpack#20963). The optionalvisitedWeakSetdeduplicates the walk when the same child is reachable through multiple parents (e.g. modules shared across chunks). (by @alexander-akait in #221)
- Implements more effective
buffersandbufferforReplaceSourceand improve performance in other places. (by @alexander-akait in #211)
- Add
Source.prototype.buffers()that returns the source asBuffer[].ConcatSource,CachedSource, andCompatSourceimplement it without allocating an intermediate concatenated buffer, allowing consumers that can write multiple buffers at once (e.g. viawritev) to avoid the overhead ofBuffer.concatin deeply nested sources. (by @alexander-akait in #204)
-
fix: use Int32Array for signed VLQ delta accumulation in
readMappingsso cumulative values that go negative are preserved instead of wrapping to a large unsigned integer (by @alexander-akait in #206) -
Improved performance in many places. (by @alexander-akait in #209)