-
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
Navigation: Improve selector performance #40700
Conversation
Size Change: -81 B (0%) Total Size: 1.23 MB
ℹ️ View Unchanged
|
const selectedBlockDescendants = getClientIdsOfDescendants( [ | ||
selectedBlockId, | ||
] ); | ||
const selectedBlockDescendants = getBlockOrder( selectedBlockId ); |
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.
I'm not sure if this is the best replacement, but it worked in my tests.
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.
I guess the difference is that getClientIdsOfDescendants
creates a deep list of clientIds (all client ids in the hierarchy below the block), and getBlockOrder
is shallow?
It doesn't seem to matter, because the code that uses this variable only checks for one child.
It might be good to rename some of the variables 'child' as 'descendants' always implies a deep search to me.
The other thing I'm wondering about is why it uses selectedBlockClientId
rather than the block's own clientId. It seems like this is used for the 'remove submenu' toolbar button that will only show if the current block is the selected one.
edit: actually, it does show when more than one submenu is selected, but seems unusable. Maybe it needs to be in a specific toolbar group.
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.
I guess the difference is that getClientIdsOfDescendants creates a deep list of clientIds (all client ids in the hierarchy below the block), and getBlockOrder is shallow?
Best to my knowledge :)
It might be good to rename some of the variables 'child' as 'descendants' always implies a deep search to me.
Good suggestion. Thanks.
Ok, so I did some thorough testing on this. I cannot speak to the code itself, but this is a HUGE improvement. See the two videos below. Before: Before.mp4After: After.mp4 |
1f31dfa
to
990985b
Compare
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.
Looks good. I can't see any issues here. From what I can tell, all of these usages seem to use the expensive descendants selector when they only need to check for immediate children.
const selectedBlockDescendants = getClientIdsOfDescendants( [ | ||
selectedBlockId, | ||
] ); | ||
const selectedBlockDescendants = getBlockOrder( selectedBlockId ); |
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.
I guess the difference is that getClientIdsOfDescendants
creates a deep list of clientIds (all client ids in the hierarchy below the block), and getBlockOrder
is shallow?
It doesn't seem to matter, because the code that uses this variable only checks for one child.
It might be good to rename some of the variables 'child' as 'descendants' always implies a deep search to me.
The other thing I'm wondering about is why it uses selectedBlockClientId
rather than the block's own clientId. It seems like this is used for the 'remove submenu' toolbar button that will only show if the current block is the selected one.
edit: actually, it does show when more than one submenu is selected, but seems unusable. Maybe it needs to be in a specific toolbar group.
@@ -459,14 +453,7 @@ export default function NavigationLinkEdit( { | |||
clientId, | |||
true | |||
), | |||
isImmediateParentOfSelectedBlock: hasSelectedInnerBlock( |
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.
Cleanup: The component wasn't using this.
false | ||
), | ||
hasDescendants: !! descendants, | ||
selectedBlockHasDescendants: !! getClientIdsOfDescendants( [ |
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.
Same for selectedBlockHasDescendants
.
62967c5
to
8da47fe
Compare
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 looks like a good improvement 🚢
* Update variable names and cleanup
I cherry picked this change into |
What?
See #40357.
PR tries to optimize the Navigation block performance.
Why?
DevTools performance tab was pointing to
rememo
andgetClientIdsWithDescendants
started. Probably recent changes to the selector affected the performance.I'm not familiar with
remomo
internals, but I think it's worth debugging separately.How?
Replaced
getClientIdsWithDescendants
withgetBlockCount
andgetBlockOrder
. Props to @mcsf for suggestion - #39985 (comment).Testing Instructions
Screenshots or screencast
After I started changing selectors
Trunk