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: https://github.com/nodejs/node/issues/55103
Signed-off-by: sangwook <rewq5991@gmail.com>
PR-URL: https://github.com/nodejs/node/pull/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>
This commit is contained in:
sangwook authored and Antoine du Hamel committed 2026-07-30 13:51:50 +02:00
1 parent 9098585c5e
commit 02fbff446f
1 file changed
+9
+9
View File
@@ -86,6 +86,7 @@ class TestCoverage {
#sourceLines = new SafeMap();
#typeScriptLines = new SafeSet();
#skipCache = new SafeMap();
getLines(fileUrl, source) {
// Split the file source into lines. Make sure the lines maintain their
@@ -535,6 +536,14 @@ class TestCoverage {
}
shouldSkipFileCoverage(url) {
const cached = this.#skipCache.get(url);
if (cached !== undefined) return cached;
const result = this.#computeShouldSkipFileCoverage(url);
this.#skipCache.set(url, result);
return result;
}
#computeShouldSkipFileCoverage(url) {
// This check filters out core modules, which start with 'node:' in
// coverage reports, as well as any invalid coverages which have been
// observed on Windows.