RTC: Fix editor freeze when replacing code editor content#76815
RTC: Fix editor freeze when replacing code editor content#76815alecgeatches merged 7 commits intotrunkfrom
Conversation
|
Size Change: +304 B (0%) Total Size: 7.69 MB
ℹ️ View Unchanged
|
|
The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs. You can also manually ask me to refresh this list by adding the If you're merging code through a pull request on GitHub, copy and paste the following into the bottom of the merge commit message. To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook. |
… We don't care about the cursor for huge performance-sensitive updates
This reverts commit 33e7aba.
|
Flaky tests detected in a46655d. 🔍 Workflow run URL: https://github.com/WordPress/gutenberg/actions/runs/23567534279
|
* Add failing performance test for huge code editor changes * Use diffLines() when strings are > 10_000 characters * Handle diffLines in diffWithCursor() when cursor information is sent. We don't care about the cursor for huge performance-sensitive updates * Explicitly use "primary" instead of "meta" key * Revert "Explicitly use "primary" instead of "meta" key" This reverts commit 33e7aba. * Fix paste keys for CI, lower timeouts * Remove console.log Co-authored-by: alecgeatches <alecgeatches@git.wordpress.org> Co-authored-by: chriszarate <czarate@git.wordpress.org>
|
I just cherry-picked this PR to the wp/7.0 branch to get it included in the next release: 90324bc |
|
I just cherry-picked this PR to the release/22.8 branch to get it included in the next release: 1ad35f8 |
…76815) * Add failing performance test for huge code editor changes * Use diffLines() when strings are > 10_000 characters * Handle diffLines in diffWithCursor() when cursor information is sent. We don't care about the cursor for huge performance-sensitive updates * Explicitly use "primary" instead of "meta" key * Revert "Explicitly use "primary" instead of "meta" key" This reverts commit 33e7aba. * Fix paste keys for CI, lower timeouts * Remove console.log Co-authored-by: alecgeatches <alecgeatches@git.wordpress.org> Co-authored-by: chriszarate <czarate@git.wordpress.org>
* Real Time Collaboration: Introduce filters for the polling intervals. (#76518) * Introduce filters for the RTC polling intervals. Introduces four filters for the polling intervals in the real time collaboration client: * `sync.pollingManager.pollingIntervalNoCollaborators` the interval in milliseconds when there are no collaborators in the room * `sync.pollingManager.pollingIntervalWithCollaborators` the interval in milliseconds when there are collaborators in the room * Remove background tab interval filter * Match filter to constant name --------- Co-authored-by: peterwilsoncc <peterwilsoncc@git.wordpress.org> Co-authored-by: chriszarate <czarate@git.wordpress.org> * RTC: Fix RichTextData deserialization (#76607) * Add failing unit test for RichTextData conversion * Fix RichText attribute type via deserializeBlockAttributes() call in getPostChangesFromCRDTDoc() * Add test for nested RichText value * Modify deserializeAttributeValue() to recurse arrays and object, using block schema for deeply nested strings * Remove deserializeBlockAttributeValues to avoid 3 different deserialization functions * Add factory wrapper for rich text cache, testing Co-authored-by: alecgeatches <alecgeatches@git.wordpress.org> Co-authored-by: chriszarate <czarate@git.wordpress.org> Co-authored-by: ingeniumed <ingeniumed@git.wordpress.org> * RTC: Scroll to collaborator on click (#76561) * Add createCursorRegistry factory and use it for scrolling to cursors * Use createCursorRegistry for scrolling * Localize spoken scroll to cursor announcement * Merge two matching conditionals * Use removeAll in cursor registry ------ Co-authored-by: maxschmeling <maxschmeling@git.wordpress.org> Co-authored-by: ingeniumed <ingeniumed@git.wordpress.org> * RTC: Change RTC option name (#76643) * Change RTC option name * Add backport changelog * Restore option migration * Cover previous option name in setCollaboration * Respect previous value in setting injection * Update migration const * Temporary bridge Co-authored-by: chriszarate <czarate@git.wordpress.org> Co-authored-by: sc0ttkclark <sc0ttkclark@git.wordpress.org> Co-authored-by: maxschmeling <maxschmeling@git.wordpress.org> Co-authored-by: ingeniumed <ingeniumed@git.wordpress.org> * RTC: Backport race condition fix (#76649) * Backport race condition fix * Add backport changelog entry * RTC: Increase polling intervals, increase polling on primary room only (#76704) * Bump polling intervals up by 4x * Reset `hasCollaborators` flag on awareness check * Use the first registered room as the primaryRoom, and only pay attention to awareness results from that entity to avoid poll increases from shared entities like categores * Simplify primaryRoom and enforceConnectionLimit * Fix the collaboration utility setup for collaboration tests --------- Co-authored-by: alecgeatches <alecgeatches@git.wordpress.org> Co-authored-by: ingeniumed <ingeniumed@git.wordpress.org> Co-authored-by: chriszarate <czarate@git.wordpress.org> Co-authored-by: t-hamano <wildworks@git.wordpress.org> * RTC: Use activation hook to enable RTC by default (#76736) * Use activation hook to enable RTC by default * Fix plugin file reference * Directly hook into the `activate_` function for enabling collaboration * Add PR backport for opt-in change --------- Co-authored-by: Alec Geatches <alec.geatches@automattic.com> * RTC: Add E2E "stress test" with complex interactions (#76055) * Add RTC E2E "stress test" with complex interactions * Refactor collab utils to work for n users instead of just 2 users * Attempting to fix the timeout, as well as the text insertion being slightly off * insert the test rather than sequentially type it * Respect the collaborators limit of 3 * Switch the type to insertText * Remove refresh as that causes editor limit exceeded * Check Gamma's movement --------- Co-authored-by: chriszarate <czarate@git.wordpress.org> Co-authored-by: ingeniumed <ingeniumed@git.wordpress.org> Co-authored-by: shekharnwagh <shekharnwagh@git.wordpress.org> * RTC: Use prepared queries instead of `*_post_meta` functions (#76779) ## What? Use prepared queries instead of `*_post_meta` functions. ## Why? Backport of WordPress/wordpress-develop#11325. Prevents post and post meta cache invalidation when RTC requests are handled. - See: https://core.trac.wordpress.org/ticket/64696 - See: https://core.trac.wordpress.org/ticket/64916 * RTC: Remove stale wp_enable_real_time_collaboration option check (#76810) Co-authored-by: shekharnwagh <shekharnwagh@git.wordpress.org> Co-authored-by: chriszarate <czarate@git.wordpress.org> * RTC: Fix editor freeze when replacing code editor content (#76815) * Add failing performance test for huge code editor changes * Use diffLines() when strings are > 10_000 characters * Handle diffLines in diffWithCursor() when cursor information is sent. We don't care about the cursor for huge performance-sensitive updates * Explicitly use "primary" instead of "meta" key * Revert "Explicitly use "primary" instead of "meta" key" This reverts commit 33e7aba. * Fix paste keys for CI, lower timeouts * Remove console.log Co-authored-by: alecgeatches <alecgeatches@git.wordpress.org> Co-authored-by: chriszarate <czarate@git.wordpress.org> * Preferences: Hide collaboration options when RTC is not enabled (#76819) * Preferences: Hide collaboration options when RTC is not enabled Only show the "Show avatar in blocks" and "Show collaboration notifications" preference controls when real-time collaboration is actually enabled for the current post. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com> * Preferences: Consolidate editorStore select call Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com> --------- Co-authored-by: t-hamano <wildworks@git.wordpress.org> Co-authored-by: chriszarate <czarate@git.wordpress.org> * Fix navigation block rendering unit test (#76685) * Fix navigation block rendering unit test * Remove semicolon Co-authored-by: t-hamano <wildworks@git.wordpress.org> Co-authored-by: westonruter <westonruter@git.wordpress.org> * Fix navigation block unit test and e2e test (#76692) * Fix navigation block rendering unit test (second try) * Fix e2e test * Revert unncessary change --------- Co-authored-by: Peter Wilson <519727+peterwilsoncc@users.noreply.github.com> Co-authored-by: peterwilsoncc <peterwilsoncc@git.wordpress.org> Co-authored-by: chriszarate <czarate@git.wordpress.org> Co-authored-by: Alec Geatches <alec.geatches@automattic.com> Co-authored-by: alecgeatches <alecgeatches@git.wordpress.org> Co-authored-by: ingeniumed <ingeniumed@git.wordpress.org> Co-authored-by: Max Schmeling <max.schmeling@automattic.com> Co-authored-by: maxschmeling <maxschmeling@git.wordpress.org> Co-authored-by: Chris Zarate <chris.zarate@automattic.com> Co-authored-by: sc0ttkclark <sc0ttkclark@git.wordpress.org> Co-authored-by: t-hamano <wildworks@git.wordpress.org> Co-authored-by: shekharnwagh <shekharnwagh@git.wordpress.org> Co-authored-by: Shekhar Wagh <shekharnwagh@gmail.com> Co-authored-by: Aki Hamano <54422211+t-hamano@users.noreply.github.com> Co-authored-by: westonruter <westonruter@git.wordpress.org>
* Add failing performance test for huge code editor changes * Use diffLines() when strings are > 10_000 characters * Handle diffLines in diffWithCursor() when cursor information is sent. We don't care about the cursor for huge performance-sensitive updates * Explicitly use "primary" instead of "meta" key * Revert "Explicitly use "primary" instead of "meta" key" This reverts commit 33e7aba. * Fix paste keys for CI, lower timeouts * Remove console.log Co-authored-by: alecgeatches <alecgeatches@git.wordpress.org> Co-authored-by: chriszarate <czarate@git.wordpress.org>
This updates the pinned hash from the `gutenberg` from `3edafcc90fc4520939d69279e26ace69390582be` to `0d133bf7e7437d65d68a06551f3d613a7d8e4361`. The following changes are included: - Reset blockEditingModes on RESET_BLOCKS (WordPress/gutenberg#76529) - RTC: Remove stale wp_enable_real_time_collaboration option check (WordPress/gutenberg#76810) - RTC: Fix editor freeze when replacing code editor content (WordPress/gutenberg#76815) - Preferences: Hide collaboration options when RTC is not enabled (WordPress/gutenberg#76819) - Editor: Fix template revisions using 'modified' date field instead of 'date' (WordPress/gutenberg#76760) - `ControlWithError`: Connect validation messages to controls via `aria… (WordPress/gutenberg#76835) A full list of changes can be found on GitHub: https://github.com/WordPress/gutenberg/compare/3edafcc90fc4520939d69279e26ace69390582be…0d133bf7e7437d65d68a06551f3d613a7d8e4361. Log created with: git log --reverse --format="- %s" 3edafcc90fc4520939d69279e26ace69390582be..0d133bf7e7437d65d68a06551f3d613a7d8e4361 | sed 's|#\([0-9][0-9]*\)|https://github.com/WordPress/gutenberg/pull/\1|g; /github\.com\/WordPress\/gutenberg\/pull/!d' | pbcopy See #64595. git-svn-id: https://develop.svn.wordpress.org/trunk@62150 602fd350-edb4-49c9-b593-d223f7449a82
This updates the pinned hash from the `gutenberg` from `3edafcc90fc4520939d69279e26ace69390582be` to `0d133bf7e7437d65d68a06551f3d613a7d8e4361`. The following changes are included: - Reset blockEditingModes on RESET_BLOCKS (WordPress/gutenberg#76529) - RTC: Remove stale wp_enable_real_time_collaboration option check (WordPress/gutenberg#76810) - RTC: Fix editor freeze when replacing code editor content (WordPress/gutenberg#76815) - Preferences: Hide collaboration options when RTC is not enabled (WordPress/gutenberg#76819) - Editor: Fix template revisions using 'modified' date field instead of 'date' (WordPress/gutenberg#76760) - `ControlWithError`: Connect validation messages to controls via `aria… (WordPress/gutenberg#76835) A full list of changes can be found on GitHub: https://github.com/WordPress/gutenberg/compare/3edafcc90fc4520939d69279e26ace69390582be…0d133bf7e7437d65d68a06551f3d613a7d8e4361. Log created with: git log --reverse --format="- %s" 3edafcc90fc4520939d69279e26ace69390582be..0d133bf7e7437d65d68a06551f3d613a7d8e4361 | sed 's|#\([0-9][0-9]*\)|https://github.com/WordPress/gutenberg/pull/\1|g; /github\.com\/WordPress\/gutenberg\/pull/!d' | pbcopy See #64595. Built from https://develop.svn.wordpress.org/trunk@62150 git-svn-id: http://core.svn.wordpress.org/trunk@61432 1a063a9b-81f0-0310-95a4-ce76da25c4cd
* Add failing performance test for huge code editor changes * Use diffLines() when strings are > 10_000 characters * Handle diffLines in diffWithCursor() when cursor information is sent. We don't care about the cursor for huge performance-sensitive updates * Explicitly use "primary" instead of "meta" key * Revert "Explicitly use "primary" instead of "meta" key" This reverts commit 33e7aba. * Fix paste keys for CI, lower timeouts * Remove console.log Co-authored-by: alecgeatches <alecgeatches@git.wordpress.org> Co-authored-by: chriszarate <czarate@git.wordpress.org>
What?
In testing, @dd32 found when editing a large page with lots of tables that using the code editor to replace the content of the page resulted in a freeze:
Screen.Recording.2026-03-25.at.1.31.00.PM.mov
This PR addresses performance issues when a huge amount of content is changed in-place in the code editor.
Why?
Our CRDT code calls into
diffWithCursor()whenY.Textupdates are made. When block content is changed in the code editor, this change is made to the document'scontentY.Textwhich results in this call. Because we don't have a cursor location for code editor changes, this resolves into a call todiff(), which internally usesdiffChars(). This is highly inefficient when the number of changes is huge.How?
This PR changes
diff()to internally usediffLines(), a line-based approach for detecting changes, when the content size is large. In testing, this makes a huge difference. Previously a ~300 line change could cause the editor to freeze for about 60 seconds locally, and ~1300 lines (the video shown above) froze the editor indefinitely. With these changes, the ~1300 line change doesn't cause a noticeable editor freeze at all:Screen.Recording.2026-03-25.at.1.33.01.PM.mov
Note that there's still a bit of render time after switching from code view before the tables are visible, but this is after the diff has successfully applied and not related, as the editor no longer hits a frozen state after pasting.
Testing Instructions
Manual testing
Download the raw versions of the included code-editor-perf-step1.md and code-editor-perf-step2.md files for manual testing.
First, switch to
trunkto reproduce the performance issue. I'm usingwp-envfor testing locally.code-editor-perf-step1.md.code-editor-perf-step2.md.Next, switch to this branch
fix/rtc-large-code-replacementand repeat the same instructions on a new post. You should not notice any freezing.Automated testing
Run:
to test the same behavior. On trunk before this change, this test failed with a 18s render time. After this fix was added, the test passes locally in <150ms.
Use of AI Tools
Claude code for writing tests