Skip to content

Commit 205295a

Browse files
Han5991aduh95
authored andcommitted
test_runner: cache shouldSkipFileCoverage result per URL
`shouldSkipFileCoverage(url)` is invoked twice for every covered script (once during source-map mapping and once during merge), and the same script URL is typically reported by every worker. The result depends only on `options.cwd`, `coverageExcludeGlobs`, and `coverageIncludeGlobs`, all of which are fixed for the lifetime of a TestCoverage instance, so the URL -> boolean mapping is deterministic and safe to cache. Add a private `#skipCache` SafeMap and split the method into a thin caching wrapper plus a private `#computeShouldSkipFileCoverage` that holds the original logic. Callers are unchanged. This eliminates redundant glob and URL parsing work proportional to the number of workers x scripts in the coverage report. Refs: #55103 Signed-off-by: sangwook <rewq5991@gmail.com> PR-URL: #63675 Reviewed-By: Matteo Collina <matteo.collina@gmail.com> Reviewed-By: Moshe Atlow <moshe@atlow.co.il> Reviewed-By: Chemi Atlow <chemi@atlow.co.il>
1 parent e7513a8 commit 205295a

1 file changed

Lines changed: 9 additions & 0 deletions

File tree

lib/internal/test_runner/coverage.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,7 @@ class TestCoverage {
8585

8686
#sourceLines = new SafeMap();
8787
#typeScriptLines = new SafeSet();
88+
#skipCache = new SafeMap();
8889

8990
getLines(fileUrl, source) {
9091
// Split the file source into lines. Make sure the lines maintain their
@@ -534,6 +535,14 @@ class TestCoverage {
534535
}
535536

536537
shouldSkipFileCoverage(url) {
538+
const cached = this.#skipCache.get(url);
539+
if (cached !== undefined) return cached;
540+
const result = this.#computeShouldSkipFileCoverage(url);
541+
this.#skipCache.set(url, result);
542+
return result;
543+
}
544+
545+
#computeShouldSkipFileCoverage(url) {
537546
// This check filters out core modules, which start with 'node:' in
538547
// coverage reports, as well as any invalid coverages which have been
539548
// observed on Windows.

0 commit comments

Comments
 (0)