Skip to content

Reuse compiled ignore matchers - #66

Open
apple-ouyang wants to merge 1 commit into
vrtmrz:mainfrom
apple-ouyang:codex/cache-ignore-matchers
Open

Reuse compiled ignore matchers#66
apple-ouyang wants to merge 1 commit into
vrtmrz:mainfrom
apple-ouyang:codex/cache-ignore-matchers

Conversation

@apple-ouyang

Copy link
Copy Markdown
Contributor

Summary

  • cache compiled Minimatch instances by ignore-list identity
  • preserve the existing isAccepted() API and matching behavior
  • add a regression test proving repeated checks reuse the two compiled pattern variants

Why

isAccepted() previously called the top-level minimatch() function for every path and pattern. That function constructs and parses a new Minimatch each 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 passed
  • npm run tsc-check
  • npm run lint (one unrelated existing warning)
  • npm run build (existing Svelte warnings only)

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
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