perf(engine): memoize glob regex compilation with bounded cache - #136
Open
iam-saiteja wants to merge 2 commits into
Open
iam-saiteja wants to merge 2 commits into
iam-saiteja wants to merge 2 commits into
Conversation
This was referenced Sep 14, 2026
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.
What Was Happening
During workspace file indexing and ripgrep search filtering, functions like
pathPatternMatches,ripgrepGlobMatches, andpathPatternMightMatchDescendantrepeatedly callglobToRegExp(pattern, caseInsensitive).Every single path check re-parsed the glob string and compiled a brand-new
RegExpobject from scratch. With hundreds of repository paths and multiple ignore or include patterns, this caused repeated regular expression compilation overhead on hot paths.What Changed
Added Bounded Regex Cache (
src/engine/utils/glob.ts)RegExpobjects in aMap<string, RegExp>with a limit of 1024 entries.i:(case-insensitive) ands:(case-sensitive) prefixes to cache keys to prevent key collisions between different sensitivity modes.Mapinsertion-order eviction to safely evict the oldest entry when reaching capacity, preventing unbounded memory growth.goryflags) soRegExp.prototype.test()has zero side effects across shared calls.Added Real-Path Benchmark (
benchmarks/glob-perf.bench.mjs)node:assert/strict.Commits
c817949:benchmarks: add real-path glob pattern matching benchmarkbenchmarks/glob-perf.bench.mjsto measure baseline matching performance across actual project paths.f670ca8:perf: memoize glob regex compilation with bounded cachesrc/engine/utils/glob.ts.benchmarks/glob-perf.bench.mjsto benchmark baseline vs optimized logic side by side and assert zero output mismatches.Performance Results (3.3 Million Pattern Evaluations)
pathPatternMatchesripgrepGlobMatchespathPatternMightMatchDescendantHow To Reproduce & Verify
Build the TypeScript source:
npm run build
Run the performance benchmark:
node benchmarks/glob-perf.bench.mjs
Run the unit test suite:
npm run test:unit
Run the linter:
npm run lint