-
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
Improve autocompleter performance #41197
Conversation
Size Change: +2 B (0%) Total Size: 1.24 MB
ℹ️ View Unchanged
|
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.
Code looks good to me and the functionality is still thre. I did not test the actual improvement b/c I trust @youknowriad 🚀
const textContent = useMemo( () => { | ||
if ( isCollapsed( record ) ) { | ||
return getTextContent( slice( record, 0 ) ); | ||
} | ||
}, [ record ] ); |
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.
Sorry, I'm probably missing the context here, but I'm curious. What's the reason for using memo
for the string value? The getTextContent
doesn't look like an expensive method.
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.
To be honest, there's no particular reason for this one but my idea was that this component is kind of a bottleneck to the less we do on rendering, the better.
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.
That makes sense. Thank you, Riad 🙇
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.
Should we add some inline comment on these preemptive hot-path optimizations in case the opposite becomes true (and running useMemo becomes more expensive)?
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 can do that 👍
…p-tests-config * 'trunk' of github.com:WordPress/gutenberg: (88 commits) Components: refactor `AlignmentMatrixControl` to pass `exhaustive-deps` (#41167) [RNMobile] Add 'Insert from URL' option to Image block (#40334) [RNMobile] Improvements to Getting Started Guides (#40964) Post Author Name: Add to and from Post Author transformations (#41151) CheckboxControl: Add unit tests (#41165) Improve inline documentation (#41209) Mobile Release v1.76.1 (#41196) Use explicit type definitions for entity configuration (#40995) Scripts: Convert file extension to js in `block.json` during build (#41068) Reflects revert in 6446878 (#41221) get_style_nodes should be compatible with parent method. (#41217) Gallery: Opt-in to axial (column/row) block spacing controls (#41175) Table of Contents block: convert line breaks to spaces in headings. (#41206) Add support for button elements to theme.json (#40260) Global Styles: Load block CSS conditionally (#41160) Update URL (#41188) Improve autocompleter performance (#41197) Site Editor: Set min-width for styles preview (#41198) Remove Navigation Editor screen from experiments page (#40878) Fix broken Page title for pages created inline within in Nav block (#41063) ...
What?
If you try to monitor keyboard typing performance in the editor, you'll notice that there's two events that constitute the "type" metric. KeyDown and KeyPress. The biggest chunk of work is happening on KeyPress but I noticed that there was a consistent 2ms time spent re-rendering the RichTextWrapper on keydown. This PR does a small refactoring that makes the keydown event last less than 1ms. I know it's a small gain and might not be visible on the metric average but small improvement + small improvement = big improvement :) (especially since this small improvement doesn't hurt the component code base at all, it's actually better this way)
Testing Instructions
Check that the block autocomplete still works as expected.