Repository navigation
Conversation
The lo-res walk searched for the next line break from the start of every unedited chunk. On a long line split into many chunks (minified code with renamed identifiers) each search ran to the end of the line, so the walk took O(chunks x line length). Reuse the previous search while the chunk starts between where it began and the line break it found. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
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.
Since v1.3.0 (#339),
generateMap()/generateDecodedMap()withouthiresslow down quadratically on long lines that are split into many chunks, i.e. minified code going through a bundler. Bundling echarts' minified ESM build with rollup 4.68 andsourcemap: truetakes about 2.5x as long ingenerate()as with this fix.Cause
The lo-res walk added in #339 finds the end of each line with
original.indexOf('\n', i)from the start of every unedited chunk. That search doesn't stop atchunk.end; it runs to the next line break in the whole string. With K chunks on a line of length L, generating the map costs O(K × L).Fix
Mappingskeeps the result of the last search with its start position and reuses it whileilies between that start and the line break it found. It recomputes when the walk goes backwards (moved chunks) or past the cached break, and the cache resets perMagicStringinaddMagicString. Hires modes are untouched. The output doesn't change.Benchmarks
Node 24.22.1, Apple M2 Max, median of 11 runs. Mappings are byte-identical before and after in every row.
rollup 4.68, echarts 6.1.0
dist/echarts.esm.min.mjs(1 MB, one line),bundle.generate()with rollup's bundled copy of magic-string patched:$1renames)$1renames)The cost of
sourcemap: truedrops from ~240 ms to ~45–65 ms.magic-string
generateMap()after overwriting every identifier, median of 7 runs:rollup / echarts benchmark
bun add rollup echarts, copynode_modules/rolluptonode_modules/rollup-patchedwith this change applied to its bundledMappings, thennode real-world.mjs rollup 11 plain,node real-world.mjs rollup-patched 11 plain(andcollide).generateMap micro-benchmark
node micro.mjs <path to dist/index.mjs>Verification
maintoo.pnpm test: 497 passed.pnpm lintandpnpm typecheckclean.main(randomoverwrite/remove/appendLeft/prependRight/move/addSourcemapLocation/updatesequences,generateMapandBundle#generateMapwithhiresfalse/true/'boundary'): 25,000 sequences, identical mappings.Relation to #383
#383 also removes this scan, as part of treating every ECMAScript line terminator as a line break, by reading line starts from the locator. This PR is the narrow perf fix on its own, with no change to output. Happy to close this if #383 lands first, or rebase whichever lands second; with this merged first, #383 would just drop the
nextNewlinehelper.This PR was prepared with the help of an AI agent (Claude Code).
🤖 Generated with Claude Code