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

Interactivity API: Hydration causes long task #58225

Closed
westonruter opened this issue Jan 25, 2024 · 1 comment · Fixed by #58227
Closed

Interactivity API: Hydration causes long task #58225

westonruter opened this issue Jan 25, 2024 · 1 comment · Fixed by #58227
Assignees
Labels
[Feature] Interactivity API API to add frontend interactivity to blocks. [Status] In Progress Tracking issues with work in progress [Type] Performance Related to performance efforts

Comments

@westonruter
Copy link
Member

westonruter commented Jan 25, 2024

Description

When there are a number of interactive blocks on the page, there is a good chance that browsers will experience a significant long task caused by init(), especially on lower-powered devices.

On a page with 20 interactive blocks and without any throttling on my HP Elite Dragonfly Chromebook (Intel i7), profiling a page load in DevTools results in a 64 ms long task (trace.cafe):

image

Not terrible, but when I throttle the CPU 6x then the task gets looooong at 309 ms (trace.cafe):

image

Reminder that a task is considered long if it is longer than 50 ms.

There is a discussion about lazy-hydration of interaction blocks in which @luisherranz acknowledges this:

It'd be great to delay the hydration of some of the interactive blocks to improve the time-to-interactive metrics of the site.

However, lazy hydration may not be sufficient if there are too many interactive blocks in the initial viewport. To deal with this, the work in the init() function could be broken up so that iteration over an interactive block yields after hydration.

Step-by-step reproduction instructions

I configured a site with 20 interactive blocks:

  • 1 Search block with "buttonPosition":"button-only","buttonUseIcon":true,"isSearchFieldHidden":true
  • 1 Navigation block with "openSubmenusOnClick":true,"overlayMenu":"always"
  • 1 Navigation block with "openSubmenusOnClick":true,"overlayMenu":"never", where there are two submenus (each of which is an interactive block), so 2 interactive blocks here
  • 1 File block with "displayPreview":true
  • 15 Image blocks with "lightbox":{"enabled":true}

Then I opened DevTools and ran performance profiling with 6x CPU throttling and without any throttling.

Screenshots, screen recording, code snippet

No response

Environment info

WordPress 6.5-alpha-57345
Gutenberg 17.6.0-rc.1
HP Dragonfly Elite Chromebook
Twenty Twenty-Three theme

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

@westonruter westonruter added [Type] Bug An existing feature does not function as intended [Feature] Interactivity API API to add frontend interactivity to blocks. labels Jan 25, 2024
@westonruter westonruter added [Type] Performance Related to performance efforts and removed [Type] Bug An existing feature does not function as intended labels Jan 25, 2024
@github-actions github-actions bot added the [Status] In Progress Tracking issues with work in progress label Jan 25, 2024
@westonruter westonruter changed the title Interactivity API: Hydration in init at DOMContentLoaded causes long task Interactivity API: Hydration causes long task Jan 25, 2024
@luisherranz
Copy link
Member

luisherranz commented Jan 25, 2024

Nice. Thanks for opening this, Weston. I also had the idea of trying a scheduler to break down the hydration 🙂

I know that Solid has had a port of React's scheduler for a while. I liked it because it is simple and has a fallback for scheduling.isInputPending. However, taking into account that the majority of low-level devices are old Android phones, we could also decide to stick to the native scheduling.isInputPending only.

I haven't looked into any of this yet, but happy to help though!

EDIT: Oh, I just noticed you already made a PR! Nice! Let's talk over there 😄

EDIT 2: I haven't read this post until now, very informative thank you. This is also simpler than I thought.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[Feature] Interactivity API API to add frontend interactivity to blocks. [Status] In Progress Tracking issues with work in progress [Type] Performance Related to performance efforts
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants