Skip to content

fix: memory leak in SCM repository context keys - #346683

Merged
Dmitriy Vasyura (dmitrivMS) merged 3 commits into
microsoft:mainfrom
SimonSiefke:fix/memory-leak-scm-repository-context
Nov 12, 2026
Merged

Dmitriy Vasyura (dmitrivMS) merged 3 commits into
microsoft:mainfrom
SimonSiefke:fix/memory-leak-scm-repository-context

Conversation

@SimonSiefke

Copy link
Copy Markdown
Contributor

Details

Creating a repository visibility key registers its repository-specific name in global context-key metadata. When the repository closes, reset keeps a false entry in the context, and both indexes keep those names.

Change

Skip metadata registration for repository-specific visibility keys and use an undefined default so reset removes the context entry.

Before

Three fresh-profile renderer trials, each with two warmup cycles and 17 measured repository close/reopen cycles, count only per-repository scmRepositoryVisible:scm… string objects. Both heap snapshots follow garbage collection; the charts show growth in shallow string bytes.

Every trial adds 17 strings (680 bytes), growing from 3 strings (120 bytes) to 20 strings (800 bytes). Heap paths lead to RawContextKey._info and context entries for closed repositories.

Before — repository visibility-key string growth in three trials

After

All three trials stay at 1 string (40 bytes), with 0 strings and 0 bytes of growth. The remaining key belongs to the active repository. Global metadata contains none of these keys, and closed-repository context entries are removed.

After — repository visibility-key string growth in three trials

Test Video

scm-repository-context-native.webm

AI disclosure: Model: GPT 6.1 Sol. Worktime: 20 min

Copilot AI balanced review requested due to automatic review settings November 6, 2026 22:59
@vs-code-engineering

Copy link
Copy Markdown
Contributor

📬 CODENOTIFY

The following users are being notified based on files changed in this PR:

Ladislau Szomoru (@lszomoru)

Matched files:

  • src/vs/workbench/contrib/scm/browser/scmViewPane.ts
  • src/vs/workbench/contrib/scm/test/browser/scmRepositoryVisibility.test.ts

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.

🟢 Approval recommended

There are no active review issues for the SCM repository visibility context-key cleanup.

No open issues 🎉

What changed in this PR

This PR fixes memory retention in SCM repository visibility context keys by preventing repository-specific names from remaining in global metadata and removing context entries when reset.

Changes:

  • Disable metadata registration and use an undefined default for repository visibility keys.
  • Add regression tests for metadata exclusion, reset cleanup, and active repository visibility expressions.
File Description
src/​vs/​workbench/​contrib/​scm/​test/​browser/​scmRepositoryVisibility.test.ts Tests metadata exclusion, key cleanup, and visibility expressions.
src/​vs/​workbench/​contrib/​scm/​browser/​scmViewPane.ts Updates visibility key defaults and disables global metadata registration.

Review effort: Balanced

@dmitrivMS Dmitriy Vasyura (dmitrivMS) added the freeze-slow-crash-leak VS Code crashing, performance, freeze and memory leak issues label Nov 6, 2026

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.

🟡 Changes recommended

The test checks only for an undefined value rather than key absence, so it can miss a retained repository-specific context key.

1 open issue

Review effort: Max

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Please consider CCR feedback.

@dmitrivMS Dmitriy Vasyura (dmitrivMS) added the scm General SCM compound issues label Nov 7, 2026
@SimonSiefke

Copy link
Copy Markdown
Contributor Author

[ai-response] Addressed the Copilot test feedback in c4b76a0: the reset regression now checks actual key removal from the context's own values, including a positive presence check before reset. The SCM visibility and ContextKeyService suites, targeted lint and hygiene pass locally. A compiled-output mutation that retains the key with undefined is caught by the strengthened test. No production code changed. Upstream CI has not been confirmed on this commit.

@SimonSiefke

Copy link
Copy Markdown
Contributor Author

Added some minor test change.

@dmitrivMS

Copy link
Copy Markdown
Collaborator
@dmitrivMS
Dmitriy Vasyura (dmitrivMS) merged commit 3543807 into microsoft:main Nov 12, 2026
52 of 53 checks passed
@vs-code-engineering vs-code-engineering Bot added this to the 1.147.0 milestone Nov 12, 2026
@SimonSiefke
Simon Siefke (SimonSiefke) deleted the fix/memory-leak-scm-repository-context branch November 13, 2026 10:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

freeze-slow-crash-leak VS Code crashing, performance, freeze and memory leak issues scm General SCM compound issues

5 participants