Skip to content

Conversation

@hendem
Copy link

@hendem hendem commented Jan 6, 2026

Fixes #3013

Summary

  • Add LRU eviction to LSP client file and diagnostics tracking maps
  • Create reusable LRUMap utility class with configurable max size

Problem

The LSP client tracks files and diagnostics in unbounded Maps. In large codebases or long sessions, these maps grow without limit, contributing to memory pressure.

Solution

Replace plain Map with LRUMap that automatically evicts least-recently-used entries when a maximum size is exceeded. Default limits:

  • Files: 1000 entries
  • Diagnostics: 500 entries

Testing

Added tests for LRUMap utility. LSP functionality preserved.

Copilot AI review requested due to automatic review settings January 6, 2026 06:02
@github-actions
Copy link
Contributor

github-actions bot commented Jan 6, 2026

The following comment was made by an LLM, it may be inaccurate:

No duplicate PRs found

Copy link
Contributor

Copilot AI left a comment

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 addresses memory leaks in the LSP client by implementing LRU (Least Recently Used) eviction for file and diagnostics tracking. It introduces a reusable LRUMap utility class and applies it to prevent unbounded memory growth during extended LSP sessions.

Key Changes:

  • Created a generic LRUMap<K, V> class with automatic eviction when capacity is exceeded
  • Applied LRU eviction to both files and diagnostics tracking with a limit of 1000 entries per LSP client
  • Added comprehensive test coverage for the LRUMap implementation

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 4 comments.

File Description
packages/opencode/src/util/lru-map.ts New LRUMap utility class implementing LRU eviction policy using JavaScript Map's insertion order guarantee
packages/opencode/test/util/lru-map.test.ts Comprehensive test suite with 10 test cases covering basic operations, eviction behavior, and edge cases
packages/opencode/src/lsp/client.ts Migrated files object and diagnostics Map to use LRUMap with MAX_TRACKED_FILES capacity

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 3 out of 3 changed files in this pull request and generated no new comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@github-actions
Copy link
Contributor

github-actions bot commented Jan 9, 2026

Thanks for your contribution!

This PR doesn't have a linked issue. All PRs must reference an existing issue.

Please:

  1. Open an issue describing the bug/feature (if one doesn't exist)
  2. Add Fixes #<number> or Closes #<number> to this PR description

See CONTRIBUTING.md for details.

Mark Henderson and others added 5 commits January 10, 2026 14:13
The LSP client's files object and diagnostics Map grew unbounded as
files were opened during a session. Every unique file path got an
entry that was never removed, causing memory to accumulate.

Changes:
- Add LRUMap utility class with configurable capacity
- Use LRUMap for both files and diagnostics tracking in LSP client
- Set MAX_TRACKED_FILES to 1000 per client
- Add comprehensive tests for LRUMap behavior

When capacity is exceeded, least recently used entries are evicted.
This bounds memory usage while keeping recently accessed files tracked.
Revert "wip: zen"

This reverts commit a8844ee9a473d14a36b352d76b9b894745dce565.
@fwang fwang force-pushed the fix/lsp-client-file-tracking-leak branch from 6ff29c1 to 1fcd656 Compare January 10, 2026 19:13
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.

Uses a huge amount of memory

2 participants