Skip to content

chat: clean up per-response maps in disposeElement to reduce memory#306482

Merged
roblourens merged 1 commit intomainfrom
copilot/impressed-cockroach
Mar 30, 2026
Merged

chat: clean up per-response maps in disposeElement to reduce memory#306482
roblourens merged 1 commit intomainfrom
copilot/impressed-cockroach

Conversation

@roblourens
Copy link
Copy Markdown
Member

Summary

Clean up accumulated per-response map entries in ChatListItemRenderer.disposeElement() to reduce memory usage.

Problem

The chat list renderer maintains several maps indexed by response/element ID:

  • codeBlocksByResponseId — code block info for each response
  • codeBlocksByEditorUri — same code block info indexed by editor URI
  • fileTreesByResponseId — file tree info for each response
  • focusedFileTreesByResponseId — focused file tree index per response

These maps accumulated entries for every rendered response but were only cleared when the entire view model changed (updateViewModel). In a long chat session, this means entries for hundreds of off-screen responses would pile up unnecessarily.

Fix

Clear these map entries in disposeElement() when elements leave the viewport. This is safe because:

  • codeBlocksByResponseId / codeBlocksByEditorUri are only read via getCodeBlockInfosForResponse() and getCodeBlockInfoForEditor(), which are called for the focused response (always visible)
  • fileTreesByResponseId / focusedFileTreesByResponseId follow the same pattern
  • When an element scrolls back into view, renderElement repopulates the data

Clear codeBlocksByResponseId, codeBlocksByEditorUri, fileTreesByResponseId,
and focusedFileTreesByResponseId when elements leave the viewport. These
maps are only read for the focused response which is always visible, so
retaining entries for off-screen elements is unnecessary memory usage.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot AI review requested due to automatic review settings March 30, 2026 21:27
Copy link
Copy Markdown
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 reduces memory usage in the chat UI by cleaning up renderer-maintained per-response lookup maps when list elements are disposed (i.e., leave the viewport), instead of only clearing them on full view model changes.

Changes:

  • Remove codeBlocksByResponseId entries during disposeElement() and attempt to remove corresponding codeBlocksByEditorUri entries.
  • Remove fileTreesByResponseId and focusedFileTreesByResponseId entries during disposeElement().

@roblourens roblourens enabled auto-merge (squash) March 30, 2026 21:35
@roblourens roblourens merged commit 8880ef4 into main Mar 30, 2026
22 checks passed
@roblourens roblourens deleted the copilot/impressed-cockroach branch March 30, 2026 21:47
@vs-code-engineering vs-code-engineering bot added this to the 1.115.0 milestone Mar 30, 2026
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.

3 participants