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

Chrome crashes after opening a category with hundreds of patterns from the pattern inserter. #50695

Closed
miksansegundo opened this issue May 17, 2023 · 5 comments
Assignees
Labels
[Feature] Inserter The main way to insert blocks using the + button in the editing interface [Feature] Patterns A collection of blocks that can be synced (previously reusable blocks) or unsynced [Type] Performance Related to performance efforts

Comments

@miksansegundo
Copy link
Contributor

Description

Chrome crashes after opening a category with 323 patterns from the pattern inserter.

The issue seems to happen because the component <BlockPatternList> loads all patterns in the background.

A solution could be loading only the pattern in the view using the hook useInView from react-intersection-observer.

Step-by-step reproduction instructions

  1. Register hundreds of patterns in a category
  2. Open the editor's pattern inserter
  3. Click on the category with hundreds of patterns
  4. Wait for a few minutes until Chrome crashes

Screenshots, screen recording, code snippet

Screen.Recording.2566-05-17.at.18.21.06.mov
@Mamaduka Mamaduka added [Type] Performance Related to performance efforts [Feature] Patterns A collection of blocks that can be synced (previously reusable blocks) or unsynced labels May 17, 2023
@gziolo gziolo added the [Feature] Inserter The main way to insert blocks using the + button in the editing interface label May 19, 2023
@aaronrobertshaw aaronrobertshaw moved this to Todo in Patterns Aug 3, 2023
@kevin940726
Copy link
Member

c.c. @youknowriad This is similar to the topic we briefly discussed. useAsyncList might not be sufficient after all?

@youknowriad
Copy link
Contributor

Do we know the reason for this crash? useAsyncList is for performance issues (not blocking the page), this might be something else memory... some pattern is doing wrong things?

@kevin940726
Copy link
Member

I think it's a combination of multiple issues: performance and memory leaks (#53382). I haven't identified most of them yet but I found something interesting.

IIRC, chrome devtools by default enable the "Disable cache" check in the network tab, which causes the same requests not to be cached when the devtools is open. Each <BlockPreview> loads the same set of stylesheets and scripts and iframes share the same request pool with the main frame. This causes the experience to degrade significantly when loading many patterns when the devtools is open.

One solution to that is to fetch the stylesheets once and cache and share them via constructable stylesheets. This technique also increases performance for other iframes.

Another possible enhancement is to replace iframes with shadow doms entirely for block previews, since iframes have more overhead than shadow doms. However, this has many edge cases that need to be considered separately.

@aaronrobertshaw
Copy link
Contributor

Quick update. A PR fixing iframe memory leaks has already been merged and a second PR adding pagination to the patterns in the inserter should land soon. Combined, these should address the crash and performance issues reported here.

@glendaviesnz
Copy link
Contributor

This should have been resolved by #54007 - please reopen if you still experience this issue on Gutenberg 16.7 or WP 6.4.

@github-project-automation github-project-automation bot moved this from In Progress to Done in Patterns Sep 27, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[Feature] Inserter The main way to insert blocks using the + button in the editing interface [Feature] Patterns A collection of blocks that can be synced (previously reusable blocks) or unsynced [Type] Performance Related to performance efforts
Projects
No open projects
Status: Done
Development

No branches or pull requests

7 participants