Patch Changes
-
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.