chat: clean up per-response maps in disposeElement to reduce memory#306482
Merged
roblourens merged 1 commit intomainfrom Mar 30, 2026
Merged
chat: clean up per-response maps in disposeElement to reduce memory#306482roblourens merged 1 commit intomainfrom
roblourens merged 1 commit intomainfrom
Conversation
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>
Contributor
There was a problem hiding this comment.
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
codeBlocksByResponseIdentries duringdisposeElement()and attempt to remove correspondingcodeBlocksByEditorUrientries. - Remove
fileTreesByResponseIdandfocusedFileTreesByResponseIdentries duringdisposeElement().
eleanorjboyd
approved these changes
Mar 30, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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 responsecodeBlocksByEditorUri— same code block info indexed by editor URIfileTreesByResponseId— file tree info for each responsefocusedFileTreesByResponseId— focused file tree index per responseThese 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/codeBlocksByEditorUriare only read viagetCodeBlockInfosForResponse()andgetCodeBlockInfoForEditor(), which are called for the focused response (always visible)fileTreesByResponseId/focusedFileTreesByResponseIdfollow the same patternrenderElementrepopulates the data