Skip to content
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

React concurrent mode can cause UI rendering to block in the sidebar inserter due to pattern previews #48084

Closed
fullofcaffeine opened this issue Feb 15, 2023 · 1 comment
Assignees
Labels
[Type] Performance Related to performance efforts

Comments

@fullofcaffeine
Copy link
Member

fullofcaffeine commented Feb 15, 2023

Description

React 18's concurrent mode has been enabled for Gutenberg at #46467. While it brings many performance benefits, it caused a UI rendering blocking/performance issue in the sidebar inserter due to too many patterns previews documents being rendered through their iframes in parallel.

Before concurrent mode, they rendered sequentially, allowing the browser to render each document in their mini-preview iframes. Now, depending on the search term being looked up in the sidebar inserter, a lot of pattern previews could be rendered at the same time/in batch (due to concurrent mode) - and depending on the browser (from my tests, it affects Firefox more) and system specs - it might cause the UI to slow down in the best case, or outright block / crash the browser in the worst case.

Step-by-step reproduction instructions

You'll need an instance of Wordpress with enough patterns registered and a search term that matches these block patterns. My instance matched ~60 patterns when searching for Image. If you use Gutenberg's wp-env instance, you won't have as many instances of block patterns that match Image, so you'll not notice any significant slowdown (if at all).

I'm using an instance where searching for Image matches 50+ block patterns. Assuming you have access to a similar environment, do the following:

Reproducing the UI bottleneck/slowness:

  1. Clone Gutenberg locally and checkout a5102012f9, build and then install/activate it in your WP instance;
  2. Open the inserter and search for the term that matches 50-60 patterns. The issue might happen with fewer patterns being rendered, but it might also be system/browser-dependent. To make sure you have the environment closest to the one I used to reproduce it, try to have at least 50 registered block patterns that have actual previews in them. An easy way to do that is to use a Wordpress.com test site, if you have access to one.
  3. Immediately after you finish typing the search term in the sidebar inserter's search box, notice how it updates the block and pattern contents below. Try to move the mouse over immediately. Notice how the hover effects render (or don't), try to scroll down/up quickly, hover over other block and pattern buttons, and take note of how the UI is rendering.

Firefox seems to have a much harder time rendering all those iframes at the same time. In my system - which is a bit dated but still quite powerful - Firefox blocked the UI several times, some of it outright crashed, and I had a complete lockdown of my OS (perhaps due to OOM errors caused by a memory leak + Firefox bug?) 3 times, when I had to force-restart the system using the power button :/. The point is that while it might not be too much of an issue for users with beefy and more recent systems with more popular browsers, it might be a real problem for users with older systems and alternative browsers.

Baseline scenario:

  1. Clone Gutenberg locally, checkout a5102012f9, and immediately revert it. Build and then install/activate it in your WP instance.
  2. Follow steps 2) to 3) from the scenario above and notice how the UI renders significantly faster/better. YMMV.

Screenshots, screen recording, code snippet

Reproducing the issue (Matching 50+ block pattern previews with React concurrent mode enabled):

with-concurrent-mode.mp4

Baseline (Matching 50+ block pattern previews without React concurrent mode):

without-concurrent-mode.mp4

Environment info

  • Wordpress 6.1(ish)
  • Firefox 110.0b9 (64-bit) and Chrome 109.0.5414.119 (Official Build) (64-bit)
  • Ubuntu Linux 20.04 LTS
  • Computer specs: i9-10885H CPU @ 2.40GHz w/ 64GB RAM

Please confirm that you have searched existing issues in the repo.

Yes

Please confirm that you have tested with all plugins deactivated except Gutenberg.

Yes

@fullofcaffeine fullofcaffeine changed the title React concurrent mode causes UI rendering to block in the sidebar inserter due to pattern previews React concurrent mode can cause UI rendering to block in the sidebar inserter due to pattern previews Feb 15, 2023
@github-actions github-actions bot added the [Status] In Progress Tracking issues with work in progress label Feb 15, 2023
@gziolo gziolo added the [Type] Performance Related to performance efforts label Feb 16, 2023
@ntsekouras
Copy link
Contributor

Fixed by: #48238

@priethor priethor removed the [Status] In Progress Tracking issues with work in progress label May 17, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[Type] Performance Related to performance efforts
Projects
None yet
4 participants