perf(core): cache TraceMap and parsed sourcemaps, use Set for coverage file lookup#1074
Merged
perf(core): cache TraceMap and parsed sourcemaps, use Set for coverage file lookup#1074
Conversation
9aoy
reviewed
Mar 19, 2026
9aoy
approved these changes
Mar 19, 2026
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
Add caching layers in the sourcemap resolution and error stack parsing paths
to eliminate redundant work when the same file is referenced by multiple
stack frames or errors within a single test run.
Not on the hot path today, but they are zero-cost correctness improvements:
Changes:
Cache
TraceMapper file in bothparseErrorStacktraceimplementations(
packages/core/src/utils/error.tsandpackages/core/src/reporter/md.ts).Avoids redundant VLQ decoding when multiple stack frames originate from the
same source file.
Memoize
JSON.parseingetSourcemap(packages/core/src/core/runTests.ts).A per-run
parsedSourceMapCacheprevents repeated parsing of the samesourcemap JSON when the same file appears in multiple errors.
Use
Set.hasinstead ofArray.includesfor coverage file lookup(
packages/core/src/coverage/generate.ts). Converts O(n) linear scans toO(1) hash lookups when filtering covered/uncovered files.
Fix
fullStackcondition inmd.tsreporter (packages/core/src/reporter/md.ts).Only re-parse the full stack when
error.fullStackis truthy, avoidingunnecessary duplicate parsing when the full stack is not requested.
All caches are scoped to per-call or per-
run()lifetime, so they areautomatically invalidated on each watch-mode rerun.
Related Links
.agents/skills/node-perf-optimization/Checklist