Skip to content

[Repo Assist] perf: cache configSearch filesystem walks in getStandard()#100

Draft
github-actions[bot] wants to merge 1 commit intomasterfrom
repo-assist/perf-configsearch-cache-2026-03-20-3967e1616eb63d66
Draft

[Repo Assist] perf: cache configSearch filesystem walks in getStandard()#100
github-actions[bot] wants to merge 1 commit intomasterfrom
repo-assist/perf-configsearch-cache-2026-03-20-3967e1616eb63d66

Conversation

@github-actions
Copy link
Contributor

🤖 This PR was created by Repo Assist, an automated AI assistant.

Summary

When phpcbf.configSearch is true, the extension searches for phpcs.xml (and 5 other ruleset file names) on every single format operation by walking up the directory tree calling fs.existsSync() at each level. For a file three directories deep this is ~18 syscalls per save; for a deeply nested project (e.g. vendor/company/module/src/) it can be 40+. With formatOnSave enabled, these filesystem calls happen on every Ctrl+S.

This PR adds a simple Map cache keyed by workspaceRoot + '\0' + fileDir so the directory walk only happens once per directory per session. The cache is cleared whenever onDidChangeConfiguration fires, ensuring fresh results if a phpcs.xml file is added or removed (requires any phpcbf setting change, or a Reload Window — standard VS Code behaviour).

Changes

extension.js

  • Added _configCache: Map field, initialised in the constructor
  • Added clearConfigCache() method (one-liner, clears the map)
  • Updated getStandard() to check the cache before calling findFiles() and to store the result (including null) after the first walk
  • Updated onDidChangeConfiguration handler to call clearConfigCache() before loadSettings() so a settings change invalidates stale cached paths

Trade-offs

Cache hits All format calls after the first for the same directory return immediately (no filesystem I/O)
Cache invalidation Cleared on any phpcbf config change via onDidChangeConfiguration — if a user adds a new phpcs.xml without changing any phpcbf setting, they'll need a Reload Window. This is the same behaviour VS Code users expect for most config-file discovery.
Correctness null results are cached too (no file found), so "file not present" directories don't re-scan.
Scope Only affects configSearch: true code path. No change when configSearch: false.

Test Status

✔ findFiles – 7 unit tests pass (npm run test:unit)

The getStandard() caching layer itself is not directly unit-tested here because PHPCBF is not currently exported. A follow-up (tracked in issue #99) exports the class and adds PHPCBF-level tests where the caching could be verified.


Relates to #17 (configSearch performance when formatOnSave is enabled)

Generated by Repo Assist ·

To install this agentic workflow, run

gh aw add githubnext/agentics/workflows/repo-assist.md@346204513ecfa08b81566450d7d599556807389f

When phpcbf.configSearch is true, getStandard() previously called
findFiles() on every format operation — a walk-up-the-directory-tree
search that calls fs.existsSync() for each of the 6 config file names
at every directory level between the document and the workspace root.
For a file three levels deep this is ~18 syscalls per Ctrl+S.

Add a Map cache keyed by 'workspaceRoot\0fileDir' so the walk only
happens once per directory per session.  The cache is cleared via
clearConfigCache() whenever onDidChangeConfiguration fires, so users
who add or remove a phpcs.xml mid-session will get fresh results after
any phpcbf configuration change (or a Reload Window).

No behaviour change for configSearch: false (the existing code path is
unchanged).

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

0 participants