-
Notifications
You must be signed in to change notification settings - Fork 37.2k
Optimize item height updates to reduce reflows and improve performance #285912
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
There was a problem hiding this 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 optimizes chat list rendering performance by batching height update operations to reduce reflows. Instead of immediately firing height change events or measuring heights synchronously, the changes are queued and processed in batched animation frames, which should improve scrolling performance when the chat view contains many code blocks.
Key changes:
- Introduced deferred batching for height change events via
pendingItemHeightChangesMap and animation frame scheduling - Introduced deferred batching for height measurements via
pendingHeightUpdatesMap and animation frame scheduling - Modified
updateItemHeightandrenderElementcall sites to use the new queuing mechanisms instead of direct/immediate updates
| const queued = Array.from(this.pendingHeightUpdates.entries()); | ||
| this.pendingHeightUpdates.clear(); | ||
| for (const [template, queuedElement] of queued) { | ||
| this.updateItemHeightOnRender(queuedElement, template); |
Copilot
AI
Jan 5, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There's a potential issue where templates stored in pendingHeightUpdates may be disposed or reused for different elements before the animation frame callback executes. When updateItemHeightOnRender is called with these stale templates at line 982, it may measure the wrong element's height or access a template that's been recycled for a different element. Consider checking if template.currentElement === queuedElement before calling updateItemHeightOnRender to ensure the template still corresponds to the queued element.
| this.updateItemHeightOnRender(queuedElement, template); | |
| // Templates may have been recycled or disposed since they were queued. | |
| // Ensure the template still corresponds to the element we queued it for. | |
| if (template.currentElement === queuedElement && template.rowContainer.isConnected) { | |
| this.updateItemHeightOnRender(queuedElement, template); | |
| } |
src/vs/workbench/contrib/chat/browser/widget/chatListRenderer.ts
Outdated
Show resolved
Hide resolved
roblourens
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the PR! I think this is basically good but we are trying to cut a release this week and I'm not brave enough to merge this for this release. I'm worried about the impact of delaying the layouts by a frame. I see this
if I close the session, reload the window, and reopen the chat session. I can debug it and merge it later.
Optimize item height updates to reduce reflows and improve performance. Related to #246523.
This is one of several PRs aimed at improving smooth scrolling in the chat view, even when it contains many code blocks.
updateItemHeightandupdateItemHeightOnRenderare one source of reflow. In this PR, reflow is reduced by deferring and batching the actual method calls to the next animation frame. There have been many complaints about scrolling in the chat view, so I think optimizations like this are well justified.When this PR not merged:
When all PRs merged: