Repository navigation
refactor(core): cache combined find index until rescan - #63454
delaysystem wants to merge 1 commit into
Conversation
There was a problem hiding this comment.
The caching itself looks correct: each rescan fills a fresh index object and only then swaps it in, and find waits for the first scan before searching. So arrays cached per index object can't go stale, and fuzzysort only reads them. I read the scan and refresh flow, ran search.test.ts and filetype.test.ts, and type-checked packages/core (typecheck:tsc, since the typecheck script failed with Script not found "check").
Public API: unchanged.
Two things to fix:
- This branch also carries
b8e5960e5(pinning the Swift highlights query, plus its test inpackages/tui). That is unrelated to the find cache and is already its own PR, #63165. Please drop it from this branch. - The new test doesn't exercise the cache (see the inline comment).
| }), | ||
| ) | ||
|
|
||
| it.effect("serves repeated finds from a cached index and drops the cache on refresh", () => |
There was a problem hiding this comment.
This test passes without the cache too: I put the base search.ts back and the suite still passes 10/10. Equal results across repeated finds, and new results after a rescan, are already how the code behaves today. The test also needs a fake Ripgrep, TestClock and a polling Effect.repeat loop, which is a lot of setup for that. The existing refresh tests already cover the rescan behaviour, so I'd drop this test. If you want to keep one, it should fail when the cache is removed, for example by checking that a repeated find doesn't rebuild the candidate arrays.
| // NOTE: Using parser repo queries instead of nvim-treesitter due to incompatible #lua-match? predicates | ||
| // "https://raw.githubusercontent.com/nvim-treesitter/nvim-treesitter/refs/heads/master/queries/highlights.scm | ||
| "https://raw.githubusercontent.com/alex-pinkus/tree-sitter-swift/main/queries/highlights.scm", | ||
| "https://raw.githubusercontent.com/alex-pinkus/tree-sitter-swift/0.7.1/queries/highlights.scm", |
There was a problem hiding this comment.
This Swift highlights change (and its filetype.test.ts test) is unrelated to the find cache. It is already open as #63165, so please remove it from this PR.
Cache the files+directories array in a WeakMap keyed by index object, invalidated atomically on index swap. Adds cache+refresh tests.
00988cc to
0e621aa
Compare
There was a problem hiding this comment.
Thanks for dropping the Swift highlights change. The PR now only touches the find cache in packages/core. Your changes to search.ts and search.test.ts are the same as before the rebase, and search.test.ts still passes.
The public API is unchanged.
The open point about the new test is still unaddressed: it passes without the cache too, so it doesn't actually check the cache.
Issue for this PR
N/A — small performance refactor, no behavior change.
Type of change
What does this PR do?
Every
findcall rebuilt the candidate arrays from the index maps (Array.fromover all files/directories). Since each scan swaps in a fresh index object atomically, this caches the files/directories/combined arrays in a WeakMap keyed by the index object, so repeated finds reuse them and the cache is naturally dropped on the next rescan. Adds cache and refresh tests.Note: this touches
packages/core/src/filesystem/search.tsin a hunk disjoint from the sibling PR fromopt/scan-prefix-incremental. They are sequenced — if that one lands first, this branch will rebase.How did you verify your code works?
Ran the focused suite in
packages/core:Checklist