feat(chunk): add pre-encoded SourceMapChunk and stitch_chunks (esbuild model)#372
Draft
Boshen wants to merge 1 commit into
Draft
feat(chunk): add pre-encoded SourceMapChunk and stitch_chunks (esbuild model)#372Boshen wants to merge 1 commit into
Boshen wants to merge 1 commit into
Conversation
Introduce the esbuild "Chunk" model: a source map whose `mappings` are already VLQ-encoded, plus the minimal delta-carry state needed to splice it into a larger map. `stitch_chunks` joins chunks by re-encoding only each chunk's first segment (and first tail name) against the running state, then copying the rest of the bytes verbatim — making concat O(modules) instead of O(tokens), with no combined `Vec<Token>` and no separate serialize pass. - `SourceMapState`: delta-carry state of a mappings stream - `SourceMap::to_chunk()`: encode mappings once, capture seam metadata - `stitch_chunks()`: O(modules) join of pre-encoded chunks - `encode_vlq_diff` made `pub(crate)` to reuse the exact VLQ primitive Validated byte-for-byte against `ConcatSourceMapBuilder` + serialize via 4 curated cases and a 2000-iteration deterministic fuzz. Infrastructure only — nothing produces `SourceMapChunk` yet.
Merging this PR will degrade performance by 2.03%
Warning Please fix the performance issues or acknowledge them on CodSpeed. Performance Changes
Tip Investigate this regression by commenting Comparing Footnotes
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
First step toward an esbuild-model source map pipeline: build the
mappingsVLQ once and join maps by stitching pre-encoded bytes, instead of materializing a combinedVec<Token>and re-serializing.SourceMapChunkmirrors esbuild'ssourcemap.Chunk— a map'smappingsalready encoded to VLQ plus the small delta-carry state needed to splice it.stitch_chunksre-encodes only each chunk's first segment (and first tail name) against the running state, then copies the rest of the bytes verbatim → O(modules) work, not O(tokens).API
SourceMapState— delta-carry state of a mappings streamSourceMap::to_chunk()— encode mappings once, capture seam metadatastitch_chunks(&[(&SourceMapChunk, line_offset)])— O(modules) join of pre-encoded chunksencode_vlq_diffmadepub(crate)to reuse the exact VLQ primitiveCorrectness
stitch_chunksoutput is asserted byte-identical to the trusted pathConcatSourceMapBuilder::from_sourcemaps(...).into_sourcemap().to_json().mappings:Notes
ConcatSourceMapBuilderalready appends names/sources wholesale (no cross-module dedup) — same as esbuild — so the stitch is byte-identical with no names tradeoff.SourceMapChunkyet. Next: aMappings::{Tokens,Encoded}representation soto_json_stringshort-circuits andSourceJoinerstitches, then route no-chain modules throughto_chunk.Draft — opening for early review of the stitch math and API shape.