-
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
useNestedSettingsUpdate: prevent unneeded syncing of falsy templateLock values #46357
Conversation
Size Change: +12 B (0%) Total Size: 1.32 MB
ℹ️ View Unchanged
|
parentLock: | ||
select( blockEditorStore ).getTemplateLock( rootClientId ), | ||
blockListSettings: getBlockListSettings( clientId ), | ||
parentLock: getTemplateLock( rootClientId ) ?? false, |
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 wonder if this should be in the selector itself? I remember I had that change in one PR that I closed at some point.
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 see you mentioned this alternative in the description of the PR. Let's just do it. I remember @jorgefilipecosta confirmed that both undefined and false are equivalent here.
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.
Performance tests show some significant improvements on this PR. The firstPaint, firstContentfulPaint, loaded and domContentLoaded metrics all go down.
I'd be doubtful about this though. I think it's probably just instability on the PR but we'll confirm it over time in the graph.
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.
OK I pushed the alternative implementation where getTemplateLock
always returns string | false
, never undefined
.
I'd be doubtful about this though. I think it's probably just instability on the PR but we'll confirm it over time in the graph.
Still, an undeniable fact is that the PR removes hundreds of cascading updateBlockListSettings
dispatches that are running after the initial render.
…from getTemplateLock
edefaac
to
fab34f3
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.
Thanks 👍
When working on #46350 I investigated how often does
useNestedSettingsUpdate
dispatch theupdateBlockListSettings
action and how these updates are batched.Testing on the
large-post.html
testing post, I see a big initial batch of 579 updates, one for each block, followed by a long series of approx 100 smaller batches, about 4 updates each. This is weird, where are all these small updates coming from?It turns out they all update a
templateLock
setting fromundefined
value tofalse
, and the affected block is always alist
orlist-item
. Indeed, thelarge-post.html
post hass approx 100 list with about 4 items each. That looks like wasted time, because in practice there's no behavior difference betweenundefined
andfalse
.These updates happen because
templateLock
is propagated down the tree from the root to leafs. Every block'stemplateLock
is either copied from parent, or sourced from the block itself, typically from a block attribute. And thelist
block enforces atemplateLock: false
setting on all its children. Therefore, anupdateBlockListSettings
on alist
changes thelist
'stemplateLock
fromundefined
tofalse
, and that triggers an update on all children, because theiruseNestedSettingsUpdate
depends on theparentLock
value.I'm fixing this by defaulting
parentLock
tofalse
. That way, none of the redundant updates will be performed. Only the meaningful updates would be done, e.g., these that update the initialfalse
value to'all'
or'contentOnly'
.And alternative fix would be to patch the
getTemplateLock
selector to returnfalse
as the default value instead ofundefined
. We don't need it to return two distinct falsy values. What do folks think about this?Performance tests show some significant improvements on this PR. The
firstPaint
,firstContentfulPaint
,loaded
anddomContentLoaded
metrics all go down.