Merged
Conversation
Identified by copilot 1. Lazy _responseRepr — Changed from eagerly rebuilt on every streaming token to computed on demand in toString(). This avoids running the expensive partsToRepr() (which iterates all parts and builds strings) on every incoming token during streaming. It's only computed when actually needed (copy, accessibility, telemetry, history). 2. Lazy _markdownContent — Same pattern: computed on demand in getMarkdown(). During streaming, getMarkdown() is called via countWords() in the view model, but crucially the string is only built once per invalidation cycle rather than eagerly on every updateContent call. If multiple parts are updated before getMarkdown() is accessed, only one computation happens. 3. _invalidateRepr() — New method that simply sets both cached strings to undefined, replacing the old _updateRepr() which did the expensive computation. 4. Response._contentChanged(quiet?) — Replaces the old _updateRepr(quiet?) override. Calls _invalidateRepr() and fires the change event when not quiet. The citation append logic moved into a computeRepr() override so it's part of the lazy computation.
Contributor
There was a problem hiding this comment.
Pull request overview
This PR applies several minor memory and performance optimizations to the chat subsystem: lazy computation of response string representations, deferred word-count updates, pre-computed render indices, shared closures/static methods to reduce allocations, and proper MutableDisposable/DisposableStore usage to fix potential disposal leaks.
Changes:
- Lazy-compute
_responseReprand_markdownContentinAbstractResponse, invalidating cached values on content change instead of eagerly rebuilding. - Replace repeated O(n) getter computations for
codeBlockStartIndex/treeStartIndexwith incrementally tracked counters, and useRunOnceSchedulerto coalesce word-count updates. - Switch to
MutableDisposable/DisposableStorefor managing rendered markdown results and highlighted labels to prevent disposal leaks on repeated updates.
Reviewed changes
Copilot reviewed 7 out of 7 changed files in this pull request and generated no comments.
Show a summary per file
| File | Description |
|---|---|
chatModel.ts |
Lazy repr/markdown computation with invalidation pattern |
chatViewModel.ts |
Coalesce word-count updates via RunOnceScheduler |
chatListRenderer.ts |
Replace O(n) getter recomputations with incremental counters |
chatThinkingContentPart.ts |
Use MutableDisposable for markdown results; hoist static helper and callback |
chatSubagentContentPart.ts |
Use MutableDisposable for title detail rendering |
chatContentMarkdownRenderer.ts |
Hoist shared closure to module level |
iconLabel.ts |
Fix disposal leak with DisposableStore for highlighted labels |
TylerLeonhardt
approved these changes
Mar 14, 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.
A collection of minor memory use optimizations from copilot