Thanks to visit codestin.com
Credit goes to github.com

Skip to content

perf(build): avoid encoding intermediate preload maps - #23461

Open
ShMcK wants to merge 3 commits into
vitejs:mainfrom
ShMcK:perf/preload-decoded-sourcemaps
Open

perf(build): avoid encoding intermediate preload maps#23461
ShMcK wants to merge 3 commits into
vitejs:mainfrom
ShMcK:perf/preload-decoded-sourcemaps

Conversation

@ShMcK

@ShMcK ShMcK commented Sep 10, 2026

Copy link
Copy Markdown

Preload rewriting generates an encoded temporary source map that combineSourcemaps immediately decodes. Use generateDecodedMap() to skip that round trip. The composer already accepts decoded maps; mapping precision (hires: 'boundary') and final encoded output stay the same.

flowchart LR
  E[Preload edits] --> B["Before: generateMap()<br/>Encode intermediate map"]
  B --> D[Decode intermediate map]
  E --> A["After: generateDecodedMap()<br/>Keep decoded mappings"]
  D --> C[Compose with original chunk map]
  A --> C
  C --> F[Encode final source map]
Loading

On a large production application with 25.5 MB of source maps, 10 measured builds per variant gave:

Median Before After Reduction
Import-analysis generateBundle hook 584.12 ms 511.57 ms 12.4%
Vite invocation, including startup 4.727 s 4.707 s 0.4%

The hook improved in all 10 paired comparisons. Overall build timings overlap substantially, so this does not establish a reliable full-build speedup. All 3,463 output files, including maps, were byte-identical across 22 builds including warmups.

Review the three files in this order:

  1. Runtime change: change map generation and its type assertion. No new dependency, option, or API.
  2. Equivalence tests: check final maps, source content, and original positions with multiple sources and relative/POSIX/Windows paths. These preserve existing behavior and pass on the baseline too.
  3. Reproducible benchmark: compare encoded/decoded composition with configurable input size.

All CI checks pass, including type checking and the Linux/macOS/Windows test matrix.

Application measurement method and local verification

Vite 8.2.0, macOS arm64, Node 22.22.2. Output: 30.8 MB JavaScript and 25.5 MB source maps across 1,389 map files (uncompressed).

One warmup build per variant, then 10 measured pairs, alternating which variant runs first. Each build uses a fresh Vite process and cleared output; dependency libraries are already built. The measured bundle task does not use Turbo caching. Both variants use the same hook instrumentation.

Hook ranges: 576.69–675.49 ms before, 490.18–533.57 ms after. Full-invocation ranges: 4.641–5.254 s before, 4.533–4.882 s after.

Verification performed locally:

  • 138 focused utility/import-analysis tests pass.
  • Eight additional temporary fixtures (not committed) produce identical code/maps: external, inline, hidden, disabled, relative base, runtime asset URLs, CSS-only preloads, and debug IDs. Fixtures also exercise Unicode, hashbangs, repeated dynamic imports, and shared dependencies.
Run the microbenchmark, including a larger source map

After installing repository dependencies:

node --import tsx packages/vite/scripts/benchPreloadSourcemap.ts
BENCH_LINES=100000 node --import tsx packages/vite/scripts/benchPreloadSourcemap.ts

The script checks output equality and measures map generation/composition through @jridgewell/remapping. It excludes Vite's path normalization and full build pipeline.

On upstream base 9913672, macOS arm64, Node 26.8.1: five fresh processes per input size, each with five warmup pairs and 20 measured pairs in alternating order. Results below are medians of process medians; map sizes include source content.

Source Original map Encoded Decoded
10,000 lines / 0.308 MB 1.82 MB 19.65 ms 18.23 ms
100,000 lines / 3.28 MB 19.37 MB 251.14 ms 198.56 ms

The larger case improved in four of five processes; one regressed (206.40 → 230.05 ms). These synthetic results are not full-build speedups or a guarantee that gains scale with map size.

AI assistance: Codex prepared the patch, tests, benchmark, and description; inspected the composition path; and ran the local checks above. Human author review is pending.

@ShMcK
ShMcK marked this pull request as ready for review September 10, 2026 04:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant