perf: add LRU refresh for configCache and prune analysisCache on document close#352
Conversation
…ment close - configCache now uses the same delete-then-re-insert LRU refresh pattern already used by analysisCache and excludeRegexCache. Previously, a hit on a configCache entry did not move it to the back of the insertion-order map, so in workspaces with 32+ folders the most-frequently-used configs could be evicted ahead of rarely-used ones. - Add pruneAnalysisCacheForDocument() method that removes all analysisCache entries for a given document URI when the document is closed. Without this, old per-version keys for closed documents survive until LRU eviction, which in active sessions with many files could push out entries for currently-open documents. The onDidCloseTextDocument listener in registerCodeLensProvider calls this to proactively reclaim memory. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
There was a problem hiding this comment.
Pull request overview
This PR improves cache behavior in the VS Code CodeLens provider to better preserve frequently-used entries and to proactively reclaim memory tied to closed documents.
Changes:
- Refresh
configCacheLRU position on cache hits (delete + reinsert) so frequently-used workspace configs are less likely to be evicted. - Add
pruneAnalysisCacheForDocument(uriString)and call it from anonDidCloseTextDocumentwatcher to remove stale per-version analysis entries for closed documents.
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #352 +/- ##
==========================================
- Coverage 74.99% 74.57% -0.43%
==========================================
Files 13 13
Lines 4063 4086 +23
Branches 434 434
==========================================
Hits 3047 3047
- Misses 1014 1037 +23
Partials 2 2 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
Co-authored-by: askpt <2493377+askpt@users.noreply.github.com>
|
@copilot the tests are failing |
Co-authored-by: askpt <2493377+askpt@users.noreply.github.com>
Fixed in commit I traced the CI failures to config state leaking between |
|
@copilot fix the ci |
Co-authored-by: askpt <2493377+askpt@users.noreply.github.com>
Fixed in commit I investigated the failing CI run ( |
🤖 This PR was created by Repo Assist, an automated AI assistant.
Summary
Two cache improvements in
codeLensProvider.ts:1. Fix LRU refresh for
configCache(Task 8 – Performance)configCachecachesCodeMetricsConfigper workspace folder. Previously, a cache hit did not refresh the entry's LRU position — unlikeanalysisCacheandexcludeRegexCachewhich both use thedelete(key)+re-insertpattern. In workspaces with 32+ folders, the most-frequently-used configs could be evicted before rarely-used ones.Fixed by applying the same
delete(key)+set(key, value)refresh on every cache hit.2. Proactive
analysisCachepruning on document close (Task 5 – Code Quality)Added
pruneAnalysisCacheForDocument(uriString)which removes allanalysisCacheentries for a given document URI prefix when the document is closed. Without this, stale per-version keys for closed documents remain until natural LRU eviction — in active sessions with many files open and closed over time, this can push out entries for currently-open documents and cause unnecessary re-parses.The new
onDidCloseTextDocumentlistener inregisterCodeLensProvidercalls this method automatically.Test Status
npm run compile— passesnpm run lint— passesnpm test— requires VS Code download (sandboxed environment); infrastructure limitation, not caused by these changesTrade-offs
Warning
Firewall blocked 1 domain
The following domain was blocked by the firewall during workflow execution:
releaseassets.githubusercontent.comSee Network Configuration for more information.
Add this agentic workflows to your repo
To install this agentic workflow, run