-
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
wp_get_global_settings
: add object cache
#3789
wp_get_global_settings
: add object cache
#3789
Conversation
cc @hellofromtonya @azaozz this is the other PR I mentioned I'd backport as early in the cycle as possible. |
Which Gutenberg PR(s) is/are covered by this? |
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.
Mostly looks good, however similar feedback from #3556 applies here. We should probably wait for that PR to land first.
@azaozz the PRs are listed in the description in the "This PR backports" section. |
Props felixarntz, aristath, ramonjd, spacedmonkey, anton-vlasenko, jorgefilipecosta, mmtr, mcsf
Rebased from |
I've shared elsewhere that I've been frustrated with the high variability of XDebug results. I know that XDebug are no real numbers, as instrumenting the PHP code adds noise. However, up until this point, I presumed the percentage of variation (whether we improve or not and the order of magnitude) would be similar to production. I no longer think this is true. I'd recommend stop taking numbers directly from cachegrind files for reporting purposes and find ways to measure a production environment (either in PHP or the reported Time To First Byte data). So I've run the same experiment (hello world post) but taking the times differently:
Run the experiment 9 times and calculated the median for these results:
|
Yep, that seems quite better way to test, not just this change but anything that's expected to be more significant. One thing I'd like to suggest is to:
Running from /build will make it as close to "production" as possible, i.e. minified js and css, etc. |
Now that This code is a clean backport from the collective work done in Gutenberg, with the merge conflicts and code requests resolved ✅ @felixarntz you previously blocked the PR. Can you please re-review and share your thoughts on if this achieves the goals and is ready for commit? |
|
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.
@oandregal I think two things here should be changed to bring this in line with the slightly cleaner code in #3712.
Also note my concern voiced in #3712 (review) that may apply here too. Let's focus on #3712 first to get that across the finish line, and then we can follow the same approach here.
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.
@oandregal This is almost good to go, however I just found one critical thing that is broken that I had missed before.
@@ -317,5 +363,6 @@ function wp_theme_has_theme_json() { | |||
*/ | |||
function wp_clean_theme_json_cache() { | |||
wp_cache_delete( 'wp_get_global_stylesheet', 'theme_json' ); | |||
wp_cache_delete( 'wp_get_global_settings', '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.
The cache clearing here is not working as it is the wrong key: We need to clear the correct cache keys for all possible origins, i.e. "wp_get_global_settings_{$origin}"
. What are the possible origins? We should probably loop through them here and clear those caches like that.
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.
Good catch, thanks! Fixed at 8a47ba6
Cross-posting here: https://core.trac.wordpress.org/ticket/57502#comment:12 This change results in an ~8% improvement in total WordPress server response time, which is amazing for a single change! 🎉 Excited to commit this once the last quirk above is addressed 😄 |
Props felixarntz, aristath, ramonjd, spacedmonkey, anton-vlasenko, jorgefilipecosta, mmtr, mcsf
I tested following Tonya's instructions and no error happens. I verified that the My env:
|
@felixarntz In my tests, classic themes (TT1) improve by 10% and block themes (TT3) improve by 25% or 40%, depending on the test (see issue description & second test with TTFB). See raw data. 8% is quite a bit lower than I expected! Could you share how did you measure? |
@oandregal Thanks for raising this. I am measuring So it is expected that those metrics are vastly different from TTFB. I would say both types of tests have their own justification, for different reasons:
So I think those methodologies complement each other well. |
…regal/wordpress-develop into update/add-cache-to-global-settings
Committed in https://core.trac.wordpress.org/changeset/55155 🎉 |
Thanks everyone for helping to land all these PRs. |
Trac ticket: https://core.trac.wordpress.org/ticket/57502
Related to WordPress/gutenberg#45171
This PR backports:
gutenberg_get_global_settings
gutenberg#45971WP_Object_Cache
to thegutenberg_get_global_settings
method gutenberg#45372theme.json
object caches non persistent gutenberg#46150Props @felixarntz, @aristath, @ramonjd, @spacedmonkey, @anton-vlasenko, @jorgefilipecosta, @mmtr, @mcsf
What
This PR adds object cache to the existing
wp_get_global_settings
.Why
This PR improves the performance of a request by:
theme.json
(from 876.05ms to 520.80ms, a total of -355.25ms)theme.json
(from 500.26ms to 450.66ms, a total of -49.60ms)After this PR, the time a theme with
theme.json
takes to process a request is almost the same (70ms slower) than a theme withouttheme.json
. See full dataset.How
Adds a cache to the high-level public method that consumers use to query the settings coming from theme.json APIs (WordPress, block, theme, and user data).
Test
add_theme_support( 'editor-color-palette', $palette )
work as expected.add_theme_support( 'disable-custom-colors' );
to thefunctions.php
of the theme. Verify that users cannot add custom colors.Performance analysis
How performance was measured
I've tested this using the same mechanism I use for all performance work I've been doing, so the impact of each PR can be compared against each other:
e27c5a38e371e1db85efeea239accf535227ed39
(svn 55005)theme.json
and TwentyTwenty for a theme with notheme.json
.I'm also sharing the raw data I extracted (cachegrind files) so anyone can open them with their tool of choice and inspect the results. Feel free to DM me if you are interested in setting this up for running the test yourself or anything.
cachegrind.out._2022_12_19_hello-world_.twentytwenty.pr.zip
cachegrind.out._2022_12_19_hello-world_.twentytwenty.trunk.zip
cachegrind.out._2022_12_19_hello-world_.twentytwentythree.pr.zip
cachegrind.out._2022_12_19_hello-world_.twentytwentythree.trunk.zip
How to reproduce the experiment yourself
You don't need to, as I've made available the cachegrind data (see section above). Though you may still want to run this yourself for peer review:
WP_DEBUG
to false:npm install && npm run build:dev
.npm run env:start && npm run env:install
.35 0442 02 * 10 = 350 442 020ns
, which amounts to350ms
.