-
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
Improve performance of global inserter: don't rerender on every attribute change. #6796
Improve performance of global inserter: don't rerender on every attribute change. #6796
Conversation
…bute change e.g: each character in a paragraph. Inserter withSelect passed many props that contain objects that change on each block attribute change eg: getBlocks. This props were only used on withDispatch. We change the withSelect to not pass all the objects but just pass the properties that in fact withDispatch uses.
} | ||
return dispatch( 'core/editor' ).insertBlock( insertedBlock, index, rootUID ); | ||
return dispatch( 'core/editor' ).insertBlock( insertedBlock, insertionPointIndex, insertionPointRootUID ); |
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 have memories of @aduth having a PR to refactor this using effects, but I'm not certain 🤷♂️
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 have memories of @aduth having a PR to refactor this using effects, but I'm not certain 🤷♂️
Refactor which? I have dreams (and local in-progress branches) of a world without explicit index and root UID arguments, though they have yet to be realized in the form of a pull request. I might have similar ones though.
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.
Thank you for clarifying this @aduth. In that case, do you think the changes here make sense or you think it is better to wait/work on bigger changes that remove the need for index and root uid arguments?
I think there's value. I've certainly noticed the flickering Inserter button when React updates are highlighted while typing. I'd guess the overall impact is small: AFAICT it should only be the top-level An alternative thought I'd had previously was maybe there'd be benefit in a higher-order component which omits certain props, since in cases like this (and others), we're injecting props which are only used in composition ( See also: Recompose documentation mention of an I'm also a bit curious the cost comparison of calling Lines 26 to 42 in a5aad35
|
That's, in fact, a disadvantage of this approach. I'm closing this PR as we are not certain if, in fact, it increases the performance. |
Inserter withSelect passed many props that contain objects that change on every block attribute change e.g.: getBlocks. These props are used only on withDispatch. We changed the withSelect not to pass complete objects but just pass the properties that in fact, withDispatch uses.
How has this been tested?
Verify the global inserter still works as expected.
Use the highlight updates browser feature to check it does not rerender on every attribute change e.g: key press in a paragraph.
Screenshots
Before:
After: