-
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
Performance improvements on append_to_selector method #47833
Conversation
Flaky tests detected in bee781c. 🔍 Workflow run URL: https://github.com/WordPress/gutenberg/actions/runs/4114291451
|
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.
The fix looks good to me. Thank you, @spacedmonkey!
Do you have a performance graph after this change is applied?
@spacedmonkey @Mamaduka @aristath I gave this a test in WordPress core
I looked into the problem a bit further, particularly in how this method is being called.
I think this change here looks good to merge for now. But I also think we should (in a separate PR) explore implementing this highly utilized method in a cleaner way. Instead of
With that, these's no if conditions anywhere, and only what is actually needed for each of the 4 scenarios is run. In all places where |
@@ -785,6 +785,9 @@ protected static function sanitize( $input, $valid_block_names, $valid_element_n | |||
* @return string The new selector. | |||
*/ | |||
protected static function append_to_selector( $selector, $to_append, $position = 'right' ) { | |||
if ( ! str_contains( ',', $selector ) ) { |
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.
Perhaps the order of the arguments is reversed?
See: https://www.php.net/manual/en/function.str-contains.php
Related: https://core.trac.wordpress.org/ticket/58193 and WordPress/wordpress-develop#4380 I'll work on porting this over to Gutenberg. |
Backport at WordPress/wordpress-develop#4412 |
Improve `append_to_selector` method in `WP_Theme_JSON` by checking to see if string contains a common before imploding / exploding string, which improves performance. Originally developed and tested in [WordPress/gutenberg#47833 Gutenberg PR 47833]. Props spacedmonkey, flixos90, mukesh27, joemcgill, wildworks, oandregal, mamaduka. Fixes #58231. git-svn-id: https://develop.svn.wordpress.org/trunk@55907 602fd350-edb4-49c9-b593-d223f7449a82
Improve `append_to_selector` method in `WP_Theme_JSON` by checking to see if string contains a common before imploding / exploding string, which improves performance. Originally developed and tested in [WordPress/gutenberg#47833 Gutenberg PR 47833]. Props spacedmonkey, flixos90, mukesh27, joemcgill, wildworks, oandregal, mamaduka. Fixes #58231. Built from https://develop.svn.wordpress.org/trunk@55907 git-svn-id: http://core.svn.wordpress.org/trunk@55419 1a063a9b-81f0-0310-95a4-ce76da25c4cd
Improve `append_to_selector` method in `WP_Theme_JSON` by checking to see if string contains a common before imploding / exploding string, which improves performance. Originally developed and tested in [WordPress/gutenberg#47833 Gutenberg PR 47833]. Props spacedmonkey, flixos90, mukesh27, joemcgill, wildworks, oandregal, mamaduka. Fixes #58231. Built from https://develop.svn.wordpress.org/trunk@55907 git-svn-id: https://core.svn.wordpress.org/trunk@55419 1a063a9b-81f0-0310-95a4-ce76da25c4cd
What?
The
append_to_selector
method is called up to 1200 times per page load.This does an explode / implode, even if the string does not need it. Do a simple check to see if the string contains a comma before doing the explode.
Why?
How?
Testing Instructions
Testing Instructions for Keyboard
Screenshots or screencast