Skip to content

Perf: Implement LRU node eviction in AsyncDataTree to prevent OOM - #332421

Open
Ayush Gupta (Ayush-kathil) wants to merge 4 commits into
microsoft:mainfrom
Ayush-kathil:perf/tree-lru-gc
Open

Perf: Implement LRU node eviction in AsyncDataTree to prevent OOM#332421
Ayush Gupta (Ayush-kathil) wants to merge 4 commits into
microsoft:mainfrom
Ayush-kathil:perf/tree-lru-gc

Conversation

@Ayush-kathil

Copy link
Copy Markdown

Fixes

Fixes #332420

Description

What this PR does:
This PR addresses OOM (Out Of Memory) crashes in the Renderer when dealing with massive workspaces by capping the memory footprint of the AsyncDataTree.

When opening massive workspaces (e.g., mono-repos with 500k+ files) or returning massive search results, expanding the Explorer tree causes the AsyncDataTree to materialize hundreds of thousands of nodes in memory. Even though the DOM is virtualized via listWidget.ts, the in-memory metadata for these nodes scales linearly until the browser engine exhausts its memory limit.

Architectural Changes:

  • Introduces a strict LRU (Least Recently Used) cache mechanism directly into src/vs/base/browser/ui/tree/asyncDataTree.ts.
  • Hooks into _onDidChangeCollapseState to track node access history.
  • Runs an asynchronous background Garbage Collector interval (performGarbageCollection).
  • When the internal node count exceeds MAX_RETAINED_NODES (default 50k), the tree automatically collapses and evicts the least recently rendered nodes outside of the current viewport.

Verification Steps

  1. Open a workspace with >500,000 files.
  2. Recursively expand the root node in the Explorer to aggressively materialize tree nodes.
  3. Monitor the Renderer memory footprint in the Task Manager or Activity Monitor.
  4. Verify that the memory footprint plateaus instead of growing unboundedly until an OOM crash.

Copilot AI balanced review requested due to automatic review settings August 24, 2026 19:40

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.

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

@vs-code-engineering

Copy link
Copy Markdown
Contributor

📬 CODENOTIFY

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

Benjamin Christopher Simmonds (@benibenj)

Matched files:

  • src/vs/base/browser/ui/tree/asyncDataTree.ts

@Ayush-kathil

Copy link
Copy Markdown
Author

@microsoft-github-policy-service agree

@Ayush-kathil
Ayush Gupta (Ayush-kathil) requested a balanced review from Copilot August 25, 2026 04:45

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.

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

@Ayush-kathil

Copy link
Copy Markdown
Author

Hi Benjamin Christopher Simmonds (@benibenj) , Kindly Look into this PR if you need further any changes please let me know

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

## [Performance] Prevent OOM crashes by implementing LRU garbage collection in AsyncDataTree

3 participants