Repository navigation
Conversation
|
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 If you're merging code through a pull request on GitHub, copy and paste the following into the bottom of the merge commit message. To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook. |
|
While I'm happy to either add a backport entry or add the |
|
Flaky tests detected in 0133986. 🔍 Workflow run URL: https://github.com/WordPress/gutenberg/actions/runs/21139484574
|
|
Hey @t-hamano! 👋 You seem to have prior experience with this feature, so is there any chance you could review this PR, or point me to a different reviewer? Thank you! |
|
@sgomes Thanks for the PR! Unfortunately, I wasn't involved much in the development of this feature 😄 Initializing on demand certainly seems like it would help, but I'd like to hear what others think. @WordPress/gutenberg-core Also, @westonruter is knowledgeable about performance improvement. |
|
Thank you so much, @t-hamano, and sorry for misunderstanding and dragging you into this! 😅 |
westonruter
left a comment
There was a problem hiding this comment.
I like this. Lazy Duotone.
Apply review suggestions from @westonruter Co-authored-by: Weston Ruter <weston@ruter.net>
sgomes
left a comment
There was a problem hiding this comment.
Thank you so much for taking a look, @westonruter!
I applied your suggestions and left some answers to your comments.
|
@sgomes, could you also submit a core-backport PR, referencing this README?
|
Co-authored-by: Weston Ruter <weston@ruter.net>
|
@westonruter : I believe I addressed all your comments, please take a look! |
|
It turns out I'm not the only one to have thought of this 🙂 When looking at backporting these changes, I noticed that @spacedmonkey already did something similar in Core back in July 2023 with this PR: WordPress/wordpress-develop@fc53820 I'm going to see if I can replicate his changes in |
|
I'm going to close this PR and start a new one based on @spacedmonkey's aforementioned changes. There is more to it than the added caching, with changes to some method signatures and behaviour that help further in avoiding unnecessary work. Sorry for missing it in the first place, and thank you for the reviews so far! |
|
I created #74748 with the changes ported from Core. |
|
I'm actually wondering if I realized that there have been many changes made exclusively in The If we want to add new features to Duotone in the future, would it be possible to add an override class to the |
That's a great question, @t-hamano, and I think it bears further investigation! I'm coming at this problem from a performance perspective ( I'll see what I can dig up as to why |
|
I tested removing However, it fails to work for block themes, which handle the block styles differently. While in classic themes the Duotone block styles are output by Duotone itself, in block themes this is handled by I'm not sure how to proceed here, other than keeping |
|
I'm afraid I wasn't involved in the development of the Duotone functionality, so I don't have any wisdom to offer. |
|
For what it's worth, this is Gemini's analysis of the issue:
|
|
Thank you, @westonruter, that does match my own analysis. So it seems that the only way we could rely on Core's implementation would be if we were to move to Core for all I'll keep working on merging the Core changes into Gutenberg (#74748) instead 👍 |
What?
Currently, the Duotone metadata initialization runs on
wp_loaded. This PR changes it to instead run the first time the metadata is needed.Why?
Computing the Duotone metadata requires running
WP_Theme_JSON_Resolver_Gutenberg::get_merged_data(), which performs a number of expensive operations across several large JSON tree structures that get loaded in from the filesystem. WhileWP_Theme_JSON_Resolver_Gutenberg::get_merged_data()relies on caching to reduce the amount of work in subsequent calls, it still takes a while to run the first time it's called for a pageview. Consequently, we want it to run as late as possible, so that we can exit before it does, if it's not needed.This PR defers the Duotone metadata computations so that they happen on-demand. While this isn't enough to avoid the expensive work in most cases, it does mean that in some special cases (such as in some PHP early exit scenarios) they can be completely avoided. It also lays the groundwork for potential future improvements that avoid them in further scenarios.
How?
This PR adds two getters with the responsibility of initializing the internal class variables, and moves all class code to using the getters instead of accessing the variables directly.
Note that despite these changes, it's still possible to call the setter methods to explicitly initialize the variables, which means that any existing external code that happens to call
WP_Duotone_Gutenberg::set_global_styles_presetsorWP_Duotone_Gutenberg::set_global_style_block_nameswill continue to work correctly.Testing Instructions
Smoke-test the Duotone feature and ensure that it continues to work correctly, by adding a Duotone filter to an image block and ensuring the page loads correctly, with the filter correctly applied.