-
Notifications
You must be signed in to change notification settings - Fork 2.7k
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 WP_Theme_JSON::merge
when merging background styles
#7486
Improve performance of WP_Theme_JSON::merge
when merging background styles
#7486
Conversation
Test using WordPress PlaygroundThe changes in this pull request can previewed and tested using a WordPress Playground instance. WordPress Playground is an experimental project that creates a full WordPress instance entirely within the browser. Some things to be aware of
For more details about these limitations and more, check out the Limitations page in the WordPress Playground documentation. |
Server-timing After the PR
The benchmarks shows that it improve the performance. Someone needs to verify the approach and the performance numbers. |
The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs. You can also manually ask me to refresh this list by adding the Core Committers: Use this line as a base for the props when committing in SVN:
To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook. |
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.
@mukeshpanchal27 While it looks like this makes sense, I noticed there is one thing missing in this PR which would cause a bug.
Once you have implemented the fix, could you please rerun the profiles to see the updated impact? We need to make sure that this is not only faster because of what is currently missing.
Server-timing After the PR implementation.
|
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.
@mukeshpanchal27 Thank you for the update.
It looks like this solution will work well, however we may want to reconsider the approach: While I initially suggested a new method, this introduces some duplicate code, which can cause problems in the future: We would need to make sure to always update the code in both methods if we want to make a change, which is not intuitive and could be easily missed.
I noticed that the existing get_block_nodes()
method has an $options
parameter. Maybe we could add an option like $node_paths_only
or similar, and if it's set we would not run most of the logic of the method that populates the other keys. WDYT?
|
||
foreach ( $theme_json['styles']['blocks'] as $name => $node ) { | ||
$nodes[] = array( | ||
'path' => array( 'styles', 'blocks', $name ), |
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.
This looks like incorrect indentation? Same below.
* @since 6.7.0 | ||
* | ||
* @param array $theme_json The theme.json converted to an array. | ||
* @return array The block nodes in theme.json. |
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.
Given this is a separate function with the only purpose to return the node paths, it would make more sense to return an array of strings, not an array of associative node arrays with only the path in it.
But we may want to reconsider the approach, per my overarching comment.
Not sure if it helps, but my understanding is that background images aren't supported for element styles yet (i.e. they're only supported for blocks themselves). Would it make it simpler to not include support for elements at this stage, then we could go with something like the first commit in this PR? Then we could revisit further down the track if or when we wished to add support for background images on elements. Just an idea, though, in case it helps wrangle the complexity. I don't want to derail the discussion if the current path is a better fix! |
In 76e0140 i introduce two option.
@felixarntz @andrewserong Could you please take look when you have moment. Thanks |
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 @mukeshpanchal27, this almost looks good to me. Just a bit of polishing needed at this point, but almost good to commit IMO.
Server-timing After the PR implementation.
|
Thanks for the updates here. Apologies if I missed some context, but it looks like this adds a fair bit of additional complexity, where the original commit took a simpler approach. Was there a reason we need to make the additional changes? Since we're only using this flag in one place, I wondered if it's worth it to try to reduce the changeset. Or were there other instances where you think we might re-use this flag? |
@andrewserong In my quick search I don't find any place where we can use these option, happy to update other places as it return lightweight version of array values. Per #7486 (comment), to add support for Ping @ramonjd as he added this feature in core and have more context. |
Can you clarify what you consider additional complexity in relation to what other version of the code? I'm not sure I understand what you're referring to. |
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.
@mukeshpanchal27 This looks good to me. One minor nit-pick, but not a blocker at all.
The original commit in c13a398 looked a little simpler to me. Not a blocker at all, but I was just trying to wrap my head around whether that approach would have been viable instead of adding the But these questions were only asked out of curiosity / to confidence check the approach. Please don't let my comments here hold up this performance improvement! |
Thank you for clarifying. I think the three checks make sense, because If we wanted to only get this data for block nodes, we could consider another parameter like you had originally proposed, but that would not really simplify the PR code, and it would introduce another parameter which we don't really know whether we need it. Hope that makes sense. |
Thanks for explaining!
Just to clarify, I wasn't meaning to advocate for another parameter — the original commit didn't include any as it skipped calling |
Thank you for working on this, folks.
This is correct. I don't see any argument to support them until we support them 😄 This is a new feature in 6.7 so I assume backwards compatibility is not on the table.
I think iterating over Having said that, I don't want to be a blocker either. The parameter addition is not a huge footprint. I just think this PR needs unit tests to support it. |
… adding tests.
If it helps, I've added one to cover the new option in the Gutenberg backport PR, if you want to port it over: Now that I've had time to reflect, I think the new option has merit as it will future-proof background image support for elements et. al. Thanks again to all! |
@felixarntz @ramonjd The feedback is addressed and PR is ready for commit. |
Background images: resolve ref and ensure appropriate default values
WP_Theme_JSON::merge
when merging background styles
Looking good to me. If no-one gets to it first, I can retest and commit tomorrow (I'm end of day). |
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.
A couple of small nitpicks, but not blockers.
It would be good to backport this to the Gutenberg plugin as well.
I'm also not seeing a big impact in the latest Performance Tests for this PR. Can we confirm that this approach still has the intended performance impact?
if ( isset( $selectors[ $name ]['duotone'] ) ) { | ||
$duotone_selector = $selectors[ $name ]['duotone']; | ||
} | ||
$include_node_paths_only = $options['include_node_paths_only'] ?? 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.
This could be moved outside of the foreach
loop since that option doesn't change
'css' => $selector, | ||
); | ||
$variation_selectors = array(); | ||
$include_variations = $options['include_block_style_variations'] ?? 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.
Similarly, this could also be set outside the loop
@joemcgill There's already a Gutenberg backport PR, see WordPress/gutenberg#66002. |
Committed in https://core.trac.wordpress.org/changeset/59213 |
… adding tests.
…erge when merging background styles (#66002) Backporting the current state of WordPress/wordpress-develop#7486 and adding tests. Co-authored-by: ramonjd <[email protected]> Co-authored-by: mukeshpanchal27 <[email protected]> Co-authored-by: felixarntz <[email protected]> Co-authored-by: andrewserong < [email protected]> Co-authored-by: joemcgill < [email protected]>
…erge when merging background styles (#66002) Backporting the current state of WordPress/wordpress-develop#7486 and adding tests. Co-authored-by: ramonjd <[email protected]> Co-authored-by: mukeshpanchal27 <[email protected]> Co-authored-by: felixarntz <[email protected]> Co-authored-by: andrewserong < [email protected]> Co-authored-by: joemcgill < [email protected]> Source: WordPress/gutenberg@2cd6929
…erge when merging background styles (#66002) Backporting the current state of WordPress/wordpress-develop#7486 and adding tests. Co-authored-by: ramonjd <[email protected]> Co-authored-by: mukeshpanchal27 <[email protected]> Co-authored-by: felixarntz <[email protected]> Co-authored-by: andrewserong < [email protected]> Co-authored-by: joemcgill < [email protected]>
…erge when merging background styles (WordPress#66002) Backporting the current state of WordPress/wordpress-develop#7486 and adding tests. Co-authored-by: ramonjd <[email protected]> Co-authored-by: mukeshpanchal27 <[email protected]> Co-authored-by: felixarntz <[email protected]> Co-authored-by: andrewserong < [email protected]> Co-authored-by: joemcgill < [email protected]>
Trac ticket: https://core.trac.wordpress.org/ticket/61858
See WordPress/performance#1572 (comment) for more details about the performance regression.
This Pull Request is for code review only. Please keep all other discussion in the Trac ticket. Do not merge this Pull Request. See GitHub Pull Requests for Code Review in the Core Handbook for more details.