Skip to content

fix(editor): defer native EditContext refresh to render time to fix large case-conversion freeze (#262473) - #310901

Merged
Aiday Marlen Kyzy (aiday-mar) merged 3 commits into
microsoft:mainfrom
maruthang:fix/issue-262473-case-conversion-freeze
Sep 22, 2026
Merged

Aiday Marlen Kyzy (aiday-mar) merged 3 commits into
microsoft:mainfrom
maruthang:fix/issue-262473-case-conversion-freeze

Conversation

@maruthang

Copy link
Copy Markdown
Contributor

What

The native EditContext is no longer synchronously refreshed from inside model/view event handlers; instead, handlers mark a dirty flag and the refresh runs once in prepareRender after all events for the edit have been dispatched.

Why

"Transform to Uppercase" / "Transform to Lowercase" over a multi-MB selection froze the editor for seconds. NativeEditContext was calling _updateEditContext() (which hands the whole primary-selection text to EditContext.updateText) synchronously from onDidChangeContent (model) and onCursorStateChanged (view) — so each event during the bulk edit pushed a megabyte-scale string into the native EditContext from the hot dispatch stack. Regression introduced by PR #298272. See #262473; Alexandru Dima (@alexdima) identified the hot path in the comments.

How

Added a _editContextNeedsRefresh boolean. onDidChangeContent and onCursorStateChanged set the flag (and call setShouldRender()) instead of invoking _updateEditContext() inline. prepareRender(ctx) drains the flag by calling _updateEditContext(), which self-clears the flag at its top. Composition-start/end paths remain synchronous — IME buffers are small and latency-sensitive, and the write there is already bounded.

Test plan (manual)

Generate a ~2 MB text file (attached sample from the issue, or python -c "print('hello world '*200000)" > big.txt). Open in VS Code built from this branch with the native EditContext enabled. Ctrl+A, F1 → "Transform to Uppercase". Before this fix: multi-second freeze. After: editor responds within a few hundred ms. Also verified: typing, IME composition, undo/redo, cursor navigation, screen-reader read-back all continue to work (screen-reader path uses the same prepareRender cadence).

Fixes #262473

@alexdima

Copy link
Copy Markdown
Member

LGTM.

Aiday Marlen Kyzy (@aiday-mar) can you pls review and try this change out, specifically that IME still works?

Copilot AI balanced review requested due to automatic review settings September 21, 2026 22:33

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Copilot review overview

🟢 Approval recommended

The deferred refresh is consistently scheduled and safely drained while preserving synchronous composition updates.

Review effort: Balanced
Findings: None

What changed in this PR

Defers expensive native EditContext synchronization to the editor render cycle, coalescing model and cursor events to prevent freezes during large case conversions.

Changes:

  • Adds a dirty flag for pending native EditContext refreshes.
  • Schedules rendering from content changes and refreshes once in prepareRender.
  • Keeps direct refreshes able to clear pending deferred work.
File Description
src/​vs/​editor/​browser/​controller/​editContext/​native/​nativeEditContext.ts Coalesces native text/selection updates at render time.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

@aiday-mar

Copy link
Copy Markdown
Collaborator

Tested. Thanks for the PR!

@aiday-mar
Aiday Marlen Kyzy (aiday-mar) merged commit 03c51d4 into microsoft:main Sep 22, 2026
33 checks passed
@vs-code-engineering vs-code-engineering Bot added this to the 1.140.0 milestone Sep 22, 2026
Abdon Morales (abdonmorales) pushed a commit to abdonmorales/vscode-utcs that referenced this pull request Sep 23, 2026
…arge case-conversion freeze (microsoft#262473) (microsoft#310901)

Co-authored-by: Dmitriy Vasyura <dmitriv@microsoft.com>
(cherry picked from commit 03c51d4)
@aiday-mar

Copy link
Copy Markdown
Collaborator

This work was recently reverted because it was wrongly believed it was causing a regression concerning inputting emojis with the windows picker. The latter issue has been traced to a chromium issue, the fix for which will be backported soon. I believe we can merge this code again, as it doesn't seem to be breaking anything. Can I ask you Maruthan G (@maruthang) if you can make the same PR again? Thank you.

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

Labels

None yet

6 participants