Skip to content

perf: cache rendered CodeLens array to skip per-call object allocation#474

Merged
askpt merged 1 commit into
mainfrom
repo-assist/perf-codelens-rendered-cache-20260724-fa471850085a7c21
Jul 24, 2026
Merged

perf: cache rendered CodeLens array to skip per-call object allocation#474
askpt merged 1 commit into
mainfrom
repo-assist/perf-codelens-rendered-cache-20260724-fa471850085a7c21

Conversation

@github-actions

Copy link
Copy Markdown
Contributor

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

Summary

provideCodeLenses was calling createCodeLenses on every invocation — even when the document content and workspace config were unchanged (cursor moves, scroll events, focus switches). Each call allocated a vscode.Range, vscode.Command, and vscode.CodeLens object for every tracked function.

This PR adds a codeLensCache that stores the rendered vscode.CodeLens[] array and returns it directly when both the document content (analysisKey) and workspace config (configKey) are unchanged.


Changes

src/providers/codeLensProvider.ts

  • New codeLensCache = Map<string, vscode.CodeLens[]> keyed by "${analysisKey}#${configKey}" (uri#langId#version#folderUri).
  • In provideCodeLenses: after resolving functions (from analysis cache or fresh parse), look up codeLensKey. Return cached lenses on hit; build and store on miss.
  • LRU eviction: bounded to ANALYSIS_CACHE_MAX_SIZE (64) entries, consistent with the analysis cache it depends on.
  • clearConfigCache(): also clears codeLensCache — threshold changes alter icon/text in every lens.
  • clearAnalysisCache(): also clears codeLensCache — language mode switches invalidate rendered lenses.
  • pruneAnalysisCacheForDocument(): also removes matching codeLensCache entries on document close.

When does this help?

VS Code calls provideCodeLenses on focus events, scroll events, and other triggers beyond text changes. With this cache:

  • Same document version + same config → zero object allocation (pure cache hit).
  • Document editedanalysisKey changes; fresh analysis + fresh render.
  • Config changed → both caches are cleared; fresh render on next call.

For a file with 50 analysed functions, each provideCodeLenses call previously allocated 50 × (1 Range + 1 Command + 1 CodeLens) = 150 objects on every cursor move. After this PR: zero.


Test Status

npm run compile  ✅  (0 errors)
npm run lint     ✅  (0 warnings)
npm run test:unit  ✅  198 passing, 0 failing

Warning

Firewall blocked 1 domain

The following domain was blocked by the firewall during workflow execution:

  • releaseassets.githubusercontent.com

To allow these domains, add them to the network.allowed list in your workflow frontmatter:

network:
  allowed:
    - defaults
    - "releaseassets.githubusercontent.com"

See Network Configuration for more information.

Generated by 🌈 Repo Assist, see workflow run. Learn more.

Add this agentic workflows to your repo

To install this agentic workflow, run

gh aw add githubnext/agentics/workflows/repo-assist.md@1c6668b751c51af8571f01204ceffb19362e0f66

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>
@askpt askpt changed the title [repo-assist] perf: cache rendered CodeLens array to skip per-call object allocation perf: cache rendered CodeLens array to skip per-call object allocation Jul 24, 2026
@codecov

codecov Bot commented Jul 24, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 0% with 42 lines in your changes missing coverage. Please review.
⚠️ Please upload report for BASE (main@e3bdcc2). Learn more about missing BASE report.

Files with missing lines Patch % Lines
src/providers/codeLensProvider.ts 0.00% 42 Missing ⚠️
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.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@askpt
askpt marked this pull request as ready for review July 24, 2026 11:27
@askpt
askpt self-requested a review as a code owner July 24, 2026 11:27
Copilot AI review requested due to automatic review settings July 24, 2026 11:27

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 codeLensCache keyed by analysisKey + workspace-folder configKey and 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
askpt merged commit b6e75a3 into main Jul 24, 2026
24 checks passed
@askpt
askpt deleted the repo-assist/perf-codelens-rendered-cache-20260724-fa471850085a7c21 branch July 24, 2026 11:33
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.

2 participants