Skip to content

Optimize rendering performance by scheduling DOM updates at the next animation frame in NativeEditContext and TextAreaEditContext#285906

Merged
aiday-mar merged 2 commits intomicrosoft:mainfrom
tamuratak:avoid_editcontext_reflow
Jan 19, 2026
Merged

Optimize rendering performance by scheduling DOM updates at the next animation frame in NativeEditContext and TextAreaEditContext#285906
aiday-mar merged 2 commits intomicrosoft:mainfrom
tamuratak:avoid_editcontext_reflow

Conversation

@tamuratak
Copy link
Contributor

Optimize rendering performance by scheduling DOM updates at the next animation frame in NativeEditContext and TextAreaEditContext. Related to #263525 and #246523.

This is one of several PRs aimed at improving smooth scrolling in the chat view, even when it contains many code blocks. NativeEditContext._updateSelectionAndControlBoundsAfterRender and TextAreaEditContext._render are one of the causes of reflow during chat view scrolling as mentioned in #263525. In this PR, reflow is avoided by deferring the actual method call 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:
editcontext_not_merged

When this PR not merged (editor.editContext: false):
editcontext_not_merged2

When all PRs merged:
allthree_merged

…animation frame in NativeEditContext and TextAreaEditContext
Copilot AI review requested due to automatic review settings January 5, 2026 10:23
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 optimizes rendering performance by deferring expensive DOM updates to the next animation frame in NativeEditContext and TextAreaEditContext, reducing reflow pressure during chat view scrolling. The changes prevent layout thrashing by scheduling DOM measurements and updates asynchronously.

  • Introduces animation frame scheduling to defer DOM updates in edit context rendering
  • Adds proper cleanup in dispose methods to prevent memory leaks
  • Maintains the same public API while optimizing internal rendering behavior

Reviewed changes

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

File Description
src/vs/editor/browser/controller/editContext/textArea/textAreaEditContext.ts Adds _scheduleRender() method to defer _render() execution to next animation frame, with proper disposal handling
src/vs/editor/browser/controller/editContext/native/nativeEditContext.ts Refactors _updateSelectionAndControlBoundsAfterRender() to schedule _applySelectionAndControlBounds() at next animation frame, with proper cleanup

private _targetWindowId: number = -1;
private _scrollTop: number = 0;
private _scrollLeft: number = 0;
private _selectionAndControlBoundsUpdateDisposable: IDisposable | undefined;
Copy link

Copilot AI Jan 5, 2026

Choose a reason for hiding this comment

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

The field _selectionAndControlBoundsUpdateDisposable uses undefined as the sentinel value, while the analogous field _scheduledRender in TextAreaEditContext uses null. For consistency across these related implementations, consider using the same sentinel value (either null or undefined) in both files.

Suggested change
private _selectionAndControlBoundsUpdateDisposable: IDisposable | undefined;
private _selectionAndControlBoundsUpdateDisposable: IDisposable | null = null;

Copilot uses AI. Check for mistakes.
@roblourens roblourens mentioned this pull request Jan 8, 2026
19 tasks
@aiday-mar aiday-mar self-requested a review January 13, 2026 09:43
@hediet hediet removed their assignment Jan 14, 2026
@aiday-mar aiday-mar enabled auto-merge (squash) January 19, 2026 09:39
@vs-code-engineering vs-code-engineering bot added this to the January 2026 milestone Jan 19, 2026
@aiday-mar aiday-mar merged commit 471da7c into microsoft:main Jan 19, 2026
17 checks passed
@alexdima
Copy link
Member

The render call for all ViewParts in the editor should already happen during animation frames, unless someone uses editor APIs that would cause forced synchronous rendering. I think I would like to be able to replay the repro to understand what is the root cause of this synchronous rendering.

@aiday-mar
Copy link
Contributor

aiday-mar commented Jan 20, 2026

Hi @tamuratak thank you for the PR. The issue you linked filed by my colleague and the performance profiles seems to suggest the slow performance is due to a recalculate styles + relayout calls triggered by the _updateSelectionAndControlBoundsAfterRender, not by the code being executed outside of an animation frame. It would seem that to improve the performance, what we could do instead is execute _updateSelectionAndControlBoundsAfterRender when the editor is focused for example, as suggested by my colleague.

I am not sure we are forcing a synchronous rendering on the editor.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants