Skip to content

perf(module-runner): extract inline source map with indexOf instead of lastIndexOf - #24159

Open
btea wants to merge 1 commit into
vitejs:mainfrom
btea:perf/module-runner-inline-sourcemap-indexof
Open

btea wants to merge 1 commit into
vitejs:mainfrom
btea:perf/module-runner-inline-sourcemap-indexof

Conversation

@btea

@btea btea commented Nov 20, 2026 •

Copy link
Copy Markdown
Contributor

V8's forward string search (indexOf) is SIMD-optimized while its backward search (lastIndexOf) is not. Since an inline source map is usually larger than the compiled code before it, lastIndexOf spends most of its time scanning the map backwards. Repeat indexOf instead to find the last match (the last sourceMappingURL wins), which keeps the existing semantics.

Benchmark (Node v26.13.1, median of 7 rounds, ~58 KB of code before the inline map):

Inline map Extraction, old → new First lookup, old → new
1 KB 0.39 → 1.08 µs 2.05 → 2.92 µs (+43%)
10 KB 2.89 → 0.56 µs 7.05 → 4.32 µs (−39%)
47 KB 13.8 → 2.24 µs 27.9 → 15.6 µs (−44%)
500 KB 153 → 14.2 µs 258 → 144 µs (−44%)
5.3 MB 1.53 → 0.15 ms 3.31 → 1.89 ms (−43%)

Follow-up to #23775

@btea btea changed the title perf(module-runner): extract inline source map with indexOf insteadof lastIndexOf perf(module-runner): extract inline source map with indexOf instead of lastIndexOf Nov 20, 2026

This branch has not been deployed

No deployments
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