[Performance] Cache compiled glob matchers in matchGlob - #8539
Draft
github-actions[bot] wants to merge 1 commit into
Draft
github-actions[bot] wants to merge 1 commit into
github-actions[bot] wants to merge 1 commit into
Conversation
minimatch() parses the pattern into a new Minimatch instance on every call. Since the same handful of patterns is matched against thousands of paths (theme ignore filters run over every file of a theme, the app file watcher over every event), that parsing dominates the cost. Compiled matchers are stateless, so they can be cached by pattern and options and reused. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
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.
WHY are these changes introduced?
matchGlobinpackages/cli-kit/src/public/node/fs.tsdelegated tominimatch(key, pattern, options), and that helper parses the pattern into a newMinimatchinstance on every single call.The callers all match the same small set of patterns against a large set of paths, so the pattern parsing — not the matching — dominates the cost:
applyIgnoreFilters(packages/theme/src/cli/utilities/asset-ignore.ts:46) runs over every file of a theme, ontheme push,theme pull, reconciliation, and remote polling.theme-fs.ts:107calls it per file-watcher event duringtheme dev.file-watcher.ts:245,325-326) andconfig-selection.ts:88,112,138match every event/path against their pattern lists.WHAT is this pull request doing?
Cache the compiled
Minimatchinstances by pattern and options, and reuse them.Minimatchinstances are stateless acrossmatch()calls, so results are unchanged — only the redundant re-parsing goes away.Measured on a synthetic 3000-file theme against 5 ignore patterns, comparing the old and new implementations in the same process (both keep an identical 2300 files):
Added
matchGlobunit tests, which had none before, covering matching, repeated use of a cached pattern, per-options cache separation, and the comment-pattern (#…) short-circuit thatminimatch()handled explicitly.How to manually test your changes?
Ignore patterns in
.shopifyignoreand--ignore/--onlyflags should behave exactly as before, with faster filtering on large themes.Checklist
patchfor bug fixes ·minorfor new features ·majorfor breaking changes) and added a changeset withpnpm changeset add