-
Notifications
You must be signed in to change notification settings - Fork 4.7k
useNestedSettingsUpdate: prevent unneeded syncing of falsy templateLock values #46357
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
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
youknowriad
left a comment
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
useNestedSettingsUpdatedispatch theupdateBlockListSettingsaction and how these updates are batched.Testing on the
large-post.htmltesting 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
templateLocksetting fromundefinedvalue tofalse, and the affected block is always alistorlist-item. Indeed, thelarge-post.htmlpost hass approx 100 list with about 4 items each. That looks like wasted time, because in practice there's no behavior difference betweenundefinedandfalse.These updates happen because
templateLockis propagated down the tree from the root to leafs. Every block'stemplateLockis either copied from parent, or sourced from the block itself, typically from a block attribute. And thelistblock enforces atemplateLock: falsesetting on all its children. Therefore, anupdateBlockListSettingson alistchanges thelist'stemplateLockfromundefinedtofalse, and that triggers an update on all children, because theiruseNestedSettingsUpdatedepends on theparentLockvalue.I'm fixing this by defaulting
parentLocktofalse. That way, none of the redundant updates will be performed. Only the meaningful updates would be done, e.g., these that update the initialfalsevalue to'all'or'contentOnly'.And alternative fix would be to patch the
getTemplateLockselector to returnfalseas 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,loadedanddomContentLoadedmetrics all go down.