[Repo Assist] perf: cache configSearch filesystem walks in getStandard()#100
Draft
github-actions[bot] wants to merge 1 commit intomasterfrom
Draft
Conversation
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>
35 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
🤖 This PR was created by Repo Assist, an automated AI assistant.
Summary
When
phpcbf.configSearchistrue, the extension searches forphpcs.xml(and 5 other ruleset file names) on every single format operation by walking up the directory tree callingfs.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+. WithformatOnSaveenabled, these filesystem calls happen on everyCtrl+S.This PR adds a simple
Mapcache keyed byworkspaceRoot + '\0' + fileDirso the directory walk only happens once per directory per session. The cache is cleared wheneveronDidChangeConfigurationfires, ensuring fresh results if aphpcs.xmlfile is added or removed (requires any phpcbf setting change, or a Reload Window — standard VS Code behaviour).Changes
extension.js_configCache: Mapfield, initialised in the constructorclearConfigCache()method (one-liner, clears the map)getStandard()to check the cache before callingfindFiles()and to store the result (includingnull) after the first walkonDidChangeConfigurationhandler to callclearConfigCache()beforeloadSettings()so a settings change invalidates stale cached pathsTrade-offs
onDidChangeConfiguration— if a user adds a newphpcs.xmlwithout changing any phpcbf setting, they'll need a Reload Window. This is the same behaviour VS Code users expect for most config-file discovery.nullresults are cached too (no file found), so "file not present" directories don't re-scan.configSearch: truecode path. No change whenconfigSearch: false.Test Status
The
getStandard()caching layer itself is not directly unit-tested here becausePHPCBFis 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)