perf: cache rendered CodeLens array to skip per-call object allocation#474
Merged
askpt merged 1 commit intoJul 24, 2026
Conversation
When neither the document content nor the workspace-folder config has changed, provideCodeLenses was re-calling createCodeLenses on every invocation — allocating a new vscode.Range, vscode.Command, and vscode.CodeLens object for every tracked function on cursor moves, scroll events, and focus switches. This PR adds a codeLensCache (Map<string, vscode.CodeLens[]>) keyed by analysisKey + configKey (uri#langId#version#folderUri). When both the analysis cache and the CodeLens cache hit, the pre-built array is returned directly without any object allocation. Cache invalidation: - clearConfigCache(): threshold/icon changes → codeLensCache.clear() - clearAnalysisCache(): language switches → codeLensCache.clear() - pruneAnalysisCacheForDocument(): document close → removes matching keys Size: bounded to ANALYSIS_CACHE_MAX_SIZE (64) entries with LRU eviction, consistent with the analysis cache it depends on. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #474 +/- ##
=======================================
Coverage ? 81.40%
=======================================
Files ? 13
Lines ? 4345
Branches ? 440
=======================================
Hits ? 3537
Misses ? 807
Partials ? 1 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
Contributor
There was a problem hiding this comment.
Pull request overview
This PR improves the VS Code extension’s runtime performance by caching the fully rendered vscode.CodeLens[] output so repeated provideCodeLenses invocations (triggered by non-text-change editor events) can avoid re-allocating Range/Command/CodeLens objects when inputs are unchanged.
Changes:
- Added an LRU-bounded
codeLensCachekeyed byanalysisKey+ workspace-folderconfigKeyand return cached lenses on hit. - Wired cache invalidation into existing config/analysis cache clearing, and pruned cached CodeLens entries on document close.
- Kept cache sizing consistent with the existing analysis cache limit (
ANALYSIS_CACHE_MAX_SIZE).
askpt
approved these changes
Jul 24, 2026
askpt
deleted the
repo-assist/perf-codelens-rendered-cache-20260724-fa471850085a7c21
branch
July 24, 2026 11:33
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 pull request was created by Repo Assist, an automated AI assistant.
Summary
provideCodeLenseswas callingcreateCodeLenseson every invocation — even when the document content and workspace config were unchanged (cursor moves, scroll events, focus switches). Each call allocated avscode.Range,vscode.Command, andvscode.CodeLensobject for every tracked function.This PR adds a
codeLensCachethat stores the renderedvscode.CodeLens[]array and returns it directly when both the document content (analysisKey) and workspace config (configKey) are unchanged.Changes
src/providers/codeLensProvider.tscodeLensCache = Map<string, vscode.CodeLens[]>keyed by"${analysisKey}#${configKey}"(uri#langId#version#folderUri).provideCodeLenses: after resolvingfunctions(from analysis cache or fresh parse), look upcodeLensKey. Return cached lenses on hit; build and store on miss.ANALYSIS_CACHE_MAX_SIZE(64) entries, consistent with the analysis cache it depends on.clearConfigCache(): also clearscodeLensCache— threshold changes alter icon/text in every lens.clearAnalysisCache(): also clearscodeLensCache— language mode switches invalidate rendered lenses.pruneAnalysisCacheForDocument(): also removes matchingcodeLensCacheentries on document close.When does this help?
VS Code calls
provideCodeLenseson focus events, scroll events, and other triggers beyond text changes. With this cache:analysisKeychanges; fresh analysis + fresh render.For a file with 50 analysed functions, each
provideCodeLensescall previously allocated 50 × (1 Range + 1 Command + 1 CodeLens) = 150 objects on every cursor move. After this PR: zero.Test Status
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