Switch from selector to useBlockEditingMode for AllowedBlocksControl#72728
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 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 blockEditingMode = useBlockEditingMode(); | ||
| const isContentOnly = blockEditingMode === 'contentOnly'; |
There was a problem hiding this comment.
@Mamaduka - I believe you mentioned somewhere that useBlockEditingMode is faster than adding getBlockEditingMode. Trying to make it stick in my brain and make sure I got it right :)
There was a problem hiding this comment.
Right. It should be preferred over custom useSelect. The useBlockEditingMode uses block context when possible and avoids creating a store subscription.
There was a problem hiding this comment.
With how many total subscriptions we maintain in runtime, I imagine the actual performance impact is hard to pinpoint? I was mostly curious how we choose what to prioritize when spending time on performance.
There was a problem hiding this comment.
In my experience, similar optimizations have a small impact and are hard to measure. These components are rendered only when the block is selected and don't create a subscription for every block on the canvas. But fixing similar paper cuts is a good thing.
I think fixes like #72496 are more impactful. The RichText can be rendered on canvas hundreds or thousands of times,
Personally, I do similar optimizations if it's a small change and doesn't complicate the logic. Otherwise, it's hard to justify complexity without real measurements.
There was a problem hiding this comment.
I share the same opinion as @Mamaduka. It's one of those bottle pickup things that is hard to measure in the moment, but is noticeable over time.
I've been looking at a lot of performance issues this week. As I happen across subscriptions that can be combined or easily prevented from running without adding complexity, I'm adding them to #72535 so I don't forget about them.
|
Size Change: -39 B (0%) Total Size: 2.37 MB
ℹ️ View Unchanged
|
Mamaduka
left a comment
There was a problem hiding this comment.
Works as expected. Couldn't spot any regressions.
What?
Minor perf - useBlockEditingMode is faster than a useSelect.
Why?
Perf
How?
instead of useSelect -> getBlockEditingMode, use useBlockEditingMode which gets the information from context (faster)
Testing Instructions
Testing Instructions for Keyboard
Screenshots or screencast