Reuse compiled ignore matchers - #66
Open
apple-ouyang wants to merge 1 commit into
Open
Conversation
Repeated path checks rebuilt the same minimatch ASTs and left oversized WeakMap backing tables in long-running vaults. Cache compiled matchers by ignore-list identity so invalidated lists can still be garbage collected without changing matching behavior. Refs vrtmrz/obsidian-livesync#1006
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.
Summary
Minimatchinstances by ignore-list identityisAccepted()API and matching behaviorWhy
isAccepted()previously called the top-levelminimatch()function for every path and pattern. That function constructs and parses a newMinimatcheach time. A heap snapshot from a long-running 60k-file vault showed twelve 64 MB backing tables retained by the bundled minimatch AST private-field WeakMaps, totaling about 768 MB.The cache is keyed by the existing ignore array with a
WeakMap, so invalidating an ignore file does not permanently retain its old patterns.Refs vrtmrz/obsidian-livesync#1006
Verification
vitest run --config vitest.config.unit.ts: 413 suites, 1368 tests passednpm run tsc-checknpm run lint(one unrelated existing warning)npm run build(existing Svelte warnings only)