-
Notifications
You must be signed in to change notification settings - Fork 4.3k
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
Block editor: optimise getGlobalBlockCount/getClientIdsWithDescendants #58356
Conversation
Size Change: +24 B (0%) Total Size: 1.7 MB
ℹ️ View Unchanged
|
9964930
to
27eb256
Compare
Flaky tests detected in 27eb256. 🔍 Workflow run URL: https://github.com/WordPress/gutenberg/actions/runs/7686964824
|
} | ||
index++; |
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.
what's the role of index
here? it doesn't seem to be tracking the end of the array, but it looks like it could intermix the ids returned in order
from different descendants.
we don't want to push these to the end of the array, right? if we insert 5 descendant ids, do we want to add the next descendants inside of those, or do we want to increment index
by 5 or 6 instead?
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.
We want to also search all the newly added clientIds for descendants, so we shouldn't increment. index
just keeps increasing until we looped over all descendants and nested descendants.
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.
so it doesn't matter in which order we add the descendent ids to the list?
did you consider using ids.push( ...order )
?
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.
It does matter :) I used push at first, but the tests were expecting the ids in a certain order (descendants right after parent ID vs after all the parent siblings
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.
okay I'm confused then, because it looks like we only get descendants immediately after their parents if there are only one descendant per parent
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.
It's deeply adding all descendants, we keep expanding the array as we find more, so the loop will also include those newly added descendants
4d58bec
to
7a98afa
Compare
}, | ||
( state ) => [ state.blocks.order ] | ||
); | ||
export const getClientIdsWithDescendants = ( state ) => |
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.
Not strictly related to your changes, but I've always thought it's awkward when writing application code that we have both of these functions. They're named similarly and I can never remember which is which. Could we deprecate getClientIdsWithDescendants
and make it so that getClientIdsOfDescendants
defaults to rootIds = ''
?
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.
Yes, it's really weird that we have both of these functions, I can deprecate it in a follow-up
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 selector has seemingly pretty good unit tests which pass and I couldn't see anything wrong while smoke testing 👍
let index = 0; | ||
|
||
// Add the descendants of the descendants, recursively. | ||
while ( index < ids.length ) { |
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 think using a stack (while ( id = stack.pop() )
) for this would be easier to grok. But I suppose you'd have to push items onto the stack in reverse order which is probably slow.
Carry on 👍
What?
Remove the recursive function calls and skip loops over empty arrays.
Too bad we cannot use the
byClientIds
apparently: #11787.Why?
Performs 20x faster on the large test post.
Also improves site editor load by ~3%.
How?
Testing Instructions
Testing Instructions for Keyboard
Screenshots or screencast