Skip to content

[Repo Assist] perf: cache settings per workspace folder to skip redundant loadSettings() calls#115

Draft
github-actions[bot] wants to merge 1 commit intomasterfrom
repo-assist/perf-settings-cache-2026-03-29-687e5440b28980fc
Draft

[Repo Assist] perf: cache settings per workspace folder to skip redundant loadSettings() calls#115
github-actions[bot] wants to merge 1 commit intomasterfrom
repo-assist/perf-settings-cache-2026-03-29-687e5440b28980fc

Conversation

@github-actions
Copy link
Copy Markdown
Contributor

🤖 This is an automated draft PR from Repo Assist, an AI assistant.

Summary

Every call to format() invokes loadSettings(document.uri) unconditionally. With formatOnSave enabled, this fires on every Ctrl+S, triggering workspace.getConfiguration() plus all downstream string-manipulation (path prefix resolution, ~ expansion, \$\{workspaceFolder} substitution) on every save — even when nothing has changed.

Root cause

loadSettings() was designed to pick up the correct scoped configuration per document so multi-root workspaces work. But once settings are loaded for a given workspace folder they remain valid until the user explicitly changes a phpcbf.* setting. There was no caching, so the work was repeated on every save.

Changes

extension.js

  • Added this._lastSettingsKey = null field in the constructor — tracks the workspace-folder URI of the last successful loadSettings() call.
  • Added clearSettingsCache() one-liner method that resets _lastSettingsKey.
  • Added early-return guard in loadSettings(): if the new call resolves to the same workspace folder as last time, skip the reload entirely.
  • Updated onDidChangeConfiguration handler to call clearSettingsCache() before loadSettings() so any settings change still triggers a fresh read.

Behaviour unchanged when:

  • A different workspace folder is opened (distinct key → settings reloaded)
  • Any phpcbf setting changes (onDidChangeConfigurationclearSettingsCache() → reload)
  • Global/no-folder workspace (key is '', guard is skipped — always reloads, conservative)

Relationship to other open PRs

This PR is complementary to existing performance PRs:

This PR eliminates the workspace.getConfiguration() call overhead on every save, which is the first thing format() does before either of the above code paths even run.

Test Status

Check Result
node --check extension.js ✅ No syntax errors
npm run test:unit (7 findFiles unit tests) ✅ All pass

(Integration tests require the VS Code GUI environment and cannot run in CI.)

Generated by Repo Assist ·

To install this agentic workflow, run

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

…ngs() calls

On every format(), loadSettings(document.uri) was called unconditionally,
triggering workspace.getConfiguration() + all downstream path-resolution
work even when settings had not changed. With formatOnSave enabled this
fires on every Ctrl+S.

Add _lastSettingsKey (workspace folder URI string) so loadSettings() is a
no-op when called again for the same workspace folder. The key is cleared
by clearSettingsCache() which is now called from onDidChangeConfiguration
so any settings change still triggers a fresh read.

Multi-root workspaces are handled correctly: distinct workspace folders have
distinct keys, so each folder's settings are loaded independently.

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