-
Notifications
You must be signed in to change notification settings - Fork 4.2k
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
Reusable blocks: fix performance of __experimentalGetAllowedPatterns #64871
Conversation
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 Unlinked AccountsThe following contributors have not linked their GitHub and WordPress.org accounts: @yunvonks, @tloureiro. Contributors, please read how to link your accounts to ensure your work is properly credited in WordPress releases. 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. |
const pattern = unlock( select( STORE_NAME ) ).getPatternBySlug( | ||
patternName | ||
); | ||
return pattern ? getParsedPattern( pattern ) : null; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is fine now without memoization, it will always return the same ref.
Size Change: -9 B (0%) Total Size: 1.77 MB
ℹ️ View Unchanged
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice simplification 👍
I just cherry-picked this PR to the wp/6.6 branch to get it included in the next release: c7f1e8e |
The Backport to WP Minor Release label was not removed; removing manually. |
What?
Should fix #64219 and #64732 (which are the same issue I think).
Why?
The editor freezes when there are thousands of reusable blocks.
How?
The problem comes from
__experimentalGetParsedPattern
, but more specifically the invalidation functiongetPatternBySlug( patternName )
, which in turn usesgetReusableBlocks()
in its invalidation function. Normally this should simply return the existing state, but maybe there's more going on in the underlyinggetEntityRecords
call.In any case,
__experimentalGetParsedPattern
is a terrible selector. It seems more appropriate to cache the parsed patterns in a weak map, which is what I did here. The performance problems seem to be resolved.Testing Instructions
Add a huge amount of reusable blocks:
Then click around the editor. What I found particularly lagging in not selecting a block but opening the appender. What I tested was the demo content, then click on the first cover and then on the + appender.
Testing Instructions for Keyboard
Screenshots or screencast