From 02fbff446f92128394be4823db0532f54b47fbb6 Mon Sep 17 00:00:00 2001 From: sangwook Date: Sun, 3 May 2026 21:57:51 +0900 Subject: [PATCH] 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 PR-URL: https://github.com/nodejs/node/pull/63675 Reviewed-By: Matteo Collina Reviewed-By: Moshe Atlow Reviewed-By: Chemi Atlow --- lib/internal/test_runner/coverage.js | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/lib/internal/test_runner/coverage.js b/lib/internal/test_runner/coverage.js index 00452377f85..80dd54d12f3 100644 --- a/lib/internal/test_runner/coverage.js +++ b/lib/internal/test_runner/coverage.js @@ -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.