Cache existing hidden directories in codeSearch to avoid redundant stat calls - #1221
Cache existing hidden directories in codeSearch to avoid redundant stat calls#1221nordicnode wants to merge 2 commits into
Conversation
|
The instinct here—avoid repeated
If you want to pursue this, I'd suggest either dropping the TTL (cache for the lifetime of a single process invocation only, invalidate on directory creation events) or making the TTL much shorter, and adding a test that actually creates/removes a directory and confirms cache behavior around that change. |
|
Thanks for the thorough and constructive review @codebuff-team! All four points have been addressed in the latest commit:
|
Summary
sdk/src/tools/code-search.ts, de-duplicate repeatedfs.statSyncinspections for blessed hidden directories (.agents,.claude,.github,.gitlab,.circleci,.husky) using a bounded in-memory cache with a 1-second burst TTL..github/or.husky/during project setup) naturally see fresh filesystem state.MAX_CACHE_SIZE = 100directories. On cache hit or insertion, entry recency is refreshed inMap; when full, the least-recently-used entry is evicted rather than clearing the whole cache.clearHiddenDirsCache(dir?)supports invalidating a specific directory or clearing all entries.fs.statSyncon 6 paths in OS cache is sub-millisecond and ripgrep process execution dominates overall search latency. This change acts as a lightweight burst de-duplication to eliminate redundant disk checks and ENOENT exceptions during rapid searches within the same directory root.sdk/src/__tests__/code-search.test.tsverifying:clearHiddenDirsCacheis called.clearHiddenDirsCacheis called.Test plan
bun test src/__tests__/code-search.test.ts(37 passed, 0 failed)bun run --cwd sdk test(542 passed, 0 failed across 41 files)bun run --cwd sdk typecheck(0 errors)bun run build:sdk(successful build)bun freebuff/cli/build.ts 0.0.0-ci(successful binary build)bun cli/scripts/smoke-binary.ts cli/bin/freebuff(OK)bun x prettier --check sdk/src/tools/code-search.ts sdk/src/__tests__/code-search.test.ts(All matched files use Prettier code style)