Skip to content

Perf: Implement tool caching to reduce filesystem I/O#19

Open
onne wants to merge 1 commit into
rawveg:mainfrom
onne:perf/tool-caching
Open

Perf: Implement tool caching to reduce filesystem I/O#19
onne wants to merge 1 commit into
rawveg:mainfrom
onne:perf/tool-caching

Conversation

@onne
Copy link
Copy Markdown

@onne onne commented May 19, 2026

Description

This PR introduces a caching layer for tool discovery in the autoloader, significantly reducing filesystem I/O and dynamic import overhead on every request.

Why this approach?

  1. Promise Caching: Instead of caching the resolved tool array, we cache the in-flight Promise. This prevents a race condition where multiple concurrent first-requests would all trigger the filesystem scan and module loading simultaneously.
  2. Immutability: The cached array is Object.freeze()'d. Since the same array reference is returned to all callers, this prevents a consumer from accidentally mutating the cached tools (e.g., pushing or sorting), which would poison the cache for future requests.
  3. Test Isolation: Exported a resetToolCache() utility to ensure tests can cleanly reset the module state without resorting to brittle vi.resetModules() gymnastics.

Resolves #17

- Discover and load all tools from the tools directory caching the promise.
- Freeze cached results to prevent mutations.
- Export resetToolCache for cleaner test isolation.
- Update tests to ensure cache consistency.
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.

Perf: Cache discovered tools to avoid redundant filesystem I/O

1 participant