lib: defer source map payload decoding until first use - #65490
Open
codebytere wants to merge 1 commit into
Open
Conversation
With source maps enabled, every module that carries a sourceMappingURL had its map decoded (or read from disk), JSON-parsed and its sources resolved to absolute URLs while the module was being loaded, and the per-line length table used for coverage was built with a per-code-point loop. None of that is needed unless a stack trace is later mapped. Keep the URL on the cache entry and resolve the payload on the first findSourceMap() for that file. Under NODE_V8_COVERAGE the payload is still resolved at load time, since the cache is serialized during shutdown. lineLengths() now splits on '\n' with indexOf and only falls back to the code point walk when the source contains U+2028/U+2029. Signed-off-by: Shelley Vohr <shelley.vohr@gmail.com>
Collaborator
|
Review requested:
|
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.
With source maps enabled, stops decoding, reading and parsing every module's source map while the module loads; the payload is resolved the first time a stack trace (or
module.findSourceMap()) needs it.benchmark/module/module-require-source-map.js(new;require()of 1000 ~45-line modules with source maps enabled), 30 runs:data:URL) maps.mapfilesUnder
--enable-source-maps,process.setSourceMapsEnabled(true)orNODE_V8_COVERAGE, every module carrying asourceMappingURLhad its map decoded from the data: URL or read from disk, JSON-parsed and itssourcesresolved while loading, and the per-line length table used for coverage was built with a per-code-point loop over the source. None of that is needed unless a stack trace through that file is later mapped, so applications that ship source maps paid for all of them at startup.The cache entry now keeps the URL and resolves the payload on the first
findSourceMap()for that file, which is what stack trace preparation andmodule.findSourceMap()go through. UnderNODE_V8_COVERAGEthe payload is still resolved at load time, since the cache is serialized during shutdown when no more JS may run.lineLengths()splits on\nwithindexOfand only falls back to the code point walk when the source contains U+2028/U+2029; its output is unchanged.Tests: existing source-map, coverage,
getCallSitesandnode-output-sourcemapstests pass unchanged; they cover mapped stack traces,findSourceMap(), invalid maps and the coverage cache serialization.Disclosure: the code, benchmark, measurements and this description were written by Claude Code, directed and reviewed by @codebytere.