perf: compile glob patterns to regexp once (Windows-safe retry of #64) #75
Open
lo1tuma wants to merge 1 commit into
Open
perf: compile glob patterns to regexp once (Windows-safe retry of #64) #75lo1tuma wants to merge 1 commit into
lo1tuma wants to merge 1 commit into
Conversation
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.
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.
Second attempt at #64. Apologies for the radio silence on the original PR.
shouldInstrumentre-parses every glob viaminimatch()on each call, which shows up as a hot path on large test suites. This compiles each pattern to aRegExponce in the constructor and reuses it.Why this didn't work the first time
minimatch()normalizes backslashes internally;minimatch.makeRe()does not. On Windows,pathToCheckarrives with\separators and never matches he precompiled forward-slash regex, that's what broke the Windows CI on #64.Fix
Normalize
\→/inpathToCheckbefore running the precompiled regex.Test
Added a test that exercises
shouldInstrumentwith backslash paths so the Windows behavior is verified on every CI run, not only on the Windows job.