Skip to content

perf: compile glob patterns to regexp once (Windows-safe retry of #64) #75

Open
lo1tuma wants to merge 1 commit into
istanbuljs:masterfrom
lo1tuma:improve-performance-v2
Open

perf: compile glob patterns to regexp once (Windows-safe retry of #64) #75
lo1tuma wants to merge 1 commit into
istanbuljs:masterfrom
lo1tuma:improve-performance-v2

Conversation

@lo1tuma
Copy link
Copy Markdown

@lo1tuma lo1tuma commented May 10, 2026

Second attempt at #64. Apologies for the radio silence on the original PR.

shouldInstrument re-parses every glob via minimatch() on each call, which shows up as a hot path on large test suites. This compiles each pattern to a RegExp once in the constructor and reuses it.

Why this didn't work the first time

minimatch() normalizes backslashes internally; minimatch.makeRe() does not. On Windows, pathToCheck arrives with \ separators and never matches he precompiled forward-slash regex, that's what broke the Windows CI on #64.

Fix

Normalize \/ in pathToCheck before running the precompiled regex.

Test

Added a test that exercises shouldInstrument with backslash paths so the Windows behavior is verified on every CI run, not only on the Windows job.

shouldInstrument was calling minimatch() per pattern per invocation, which
shows up as a hot path in coverage runs over large test suites.

Compile each include/exclude/excludeNegated pattern to a RegExp once during
construction and reuse them on every shouldInstrument call. The matcher then
runs RegExp.prototype.test instead of re-parsing globs.

Previous attempt (istanbuljs#64) failed on Windows because minimatch.makeRe produces
regexes against forward-slash paths, but Windows paths use backslashes —
minimatch() normalized internally, the precompiled regex did not. Normalize
backslashes to forward slashes in pathToCheck before testing.

Adds a test that drives shouldInstrument with backslash paths so the
Windows code path is exercised on every CI run, not only on the Windows job.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant