-
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
Add WP_Object_Cache
to the gutenberg_get_global_settings
method
#45372
Conversation
Open in CodeSandbox Web Editor | VS Code | VS Code Insiders |
gutenberg_get_global_settings
methodgutenberg_get_global_settings
method
@ramonjd @andrewserong @scruffian @tellthemachines @noisysocks I'm working on this PR and the only test failures are related to I need to look at them deeply, but thought you may be able to offer some quick thoughts. |
3c0ca52
to
a1d9632
Compare
I can look more closely next week, but does this PR changes the way we resolve the theme.json for the test theme we're using in the typography tests? The tests are failing because "typography": {
"fluid": true
} |
Some initial notes to invalidate the cache for settings & styles:
|
I've extracted two small PRs that we can fast-track and land separately:
The goal of this PR should be simply adding object cache to this method. |
b11761c
to
178ed79
Compare
We talked about this at length in a recent private conversation, as well as in a few other PRs 🙂 I'm happy to discuss the direction, though at some point we need to move forward with something. If we can't agree on direction, we need to disagree and commit. Being caught in an eternal loop is not fun for anyone. We already have caching in |
@oandregal Can you explain why we are caching the same data twice? What is the benefit of this? The reason it keeps coming up, I don’t feel like you have explained yourself in enough detail that I feel like I can drop this. Caching the same data twice, is strange and makes cache invalidation harder, you have two caches to worry about. Not to mention, more memory used in both object cache and in persistent object caches. As for the fact we discussed this privately, that is part of the reason I am mentioning it again, so we can discuss, with other involved the reasoning behind this code. This conversion is public and future developers will benefit it being documented. |
Absolutely. I've been doing for a month now across many issues, so I've got some practice 🙂 We are caching different data: one is a CSS stylesheet, the other is an array of data. While they access the same source of data ( |
e00e39f
to
a8b2676
Compare
I am just catching up on all those issues. There is no one place I feel like you have explained this issue in detail. So I am still trying to understand your thinking. To zoom out a little, the performance issue is in Lots of work was done by @aristath to make theme json performance faster. See WordPress/wordpress-develop#3555. So the core issue of performance is where we should focus our work. This is adding a cache, upstream from the core issue. Like putting a band aid over the issue, instead of treating the larger issue. The point of the cache, is stop the expensive compute in Let's focus on the core issue and not to cover it up with caches. |
Hey, I shared as much as possible in all the places people asked me to (issues, PRs, slack, DMs, video, etc.), including in long-form at #45171 If the fact that caching a generated CSS stylesheet and caching an array are two separate things is not obvious, I don't know what else to say to be honest 😞 I may need some time away or hear other voices to learn how to rephrase it and make it more obvious. We all may need to ruminate about this for a few days, so I'm going to refrain to comment on what I've already shared about direction for a bit.
I have also humbly contributed a little bit (in addition to all recent Gutenberg PRs) 🙂
All those changes are great and I welcome them. They have not been enough so far. I wish they were! None has brought a 35% performance improvement like this PR does. |
To be clear, I understand what is being cached here. That is never been in question. The question is why, why are we caching? The answer, is the WP_Theme_Json_Resolver class, has performance issues. That is what we need to fix here. Once those performance issues are fixed, then we can call I want to fix the root cause of this issue. I think this is going to be really hard to go, within the gutenberg plugin, as it relays deep integrations into the WordPress bootstrap and theming process. |
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, thank you for all this work that is bringing an incredible improvement of 35% on the time the engine takes to output a page.
When we see improvements of this magnitude, we should do what we can in order to ship them as fast as possible to our users.
It seems an improvement discussed was the invalidation on-site options change which I think makes total sense.
Another aspect was that when we change a file, if there is object cache persistence on the last reload, the file change is still not applied. I guess we could add theme-json to the non-persistent cache groups like the theme is.
Or we could later explore including the last modified timestamp of the theme-json file as part of the cache key.
Provided we include these two enhancements I don't see any other clear blocker.
I created a complementary PR that should remove a lot of calls to get_merged_data #46074. |
Ideally, we'd just rewrite
I agree 100%!! This task will take months and can't be implemented before the WP6.2 release - if we even make it for that release and it doesn't go in 6.3. In the meantime, we can use this solution to dramatically improve performance until we come up with a better implementation. This PR presents a dramatic improvement, it should not be ignored or dismissed.
I think that the If in the future, we see that this cache is no longer needed, we can remove it. But in my opinion, we could/should merge this with a couple of tweaks.
Other than those 2 small tweaks, this PR looks good to me, and I'd support merging it in a heartbeat. |
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 is a great improvement and should find it's way into core, ASAP.
Before merging, this here, should need to group the cache group the data is saved into non persistent. Making it non persistent is going to solve a lot of cache invalidation issues, as data is not saved per request. It means we can make quickly follow up with another solution for how we handle dynamically removing / add theme supports. This can be done in another PR, but is a blocker to a core merge, it will make core unit tests fail.
As for adding wrappers for all these cache invalidation, this can also be done in a single PR or on core merge.
Are their trac tickets are all these changes? We need to start working on how we are going to merge this changes into core.
I would also like to see #46112 merged first if possible. This shaves around 11-15% of page load. I wonder how much of the performance wins of this change are just covering up this bug. |
Made the |
d8996f6
to
783e57b
Compare
783e57b
to
d115157
Compare
All dependencies have landed and all the feedback has been addressed. This is ready for a final ✔️ (It'd be lovely if it lands this morning to make it part of 14.7: I've potentially marked it for that milestone). |
I've done a final testing, including (plus some other random actions):
Everything works as expected. All feedback in this blocking review has been addressed. Jonny may have limited availability to clear it, so, in the interest of making this PR part of 14.7 RC, I'm going to merge. If there are any bugs I didn't find, we still have a week to fix them (or revert this PR, should it be necessary). Thanks everyone for the feedback, let's ship this to users. |
Part of #45171
Depends on:
gutenberg_get_global_settings
#45971theme.json
object caches non persistent #46150What?
This PR uses
WP_Object_Cache
to cache the results of querying settings from thetheme.json
.Why?
This PR reduces the total time of a request from 521.59ms to 339.62ms, a ~35% performance increase.
How?
Adds a cache to the high-level public method that consumers use to query the settings coming from
theme.json
APIs (WordPress, theme, and user data).How performance was measured
To measure performance, I have loaded the "Hello World!" post as a logged-out user under the following scenarios:
ee90c2b1df7cb59e1f6ea3e2aaeb3b15386396ac
For each Gutenberg branch, I have conducted the test 9 times and then calculated the median to get the time for the request. Download the data for:
How to reproduce the performance measures
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:
WP_DEBUG
andSCRIPT_DEBUG
to false by creating a.wp-env.override.json
file with the following contents:npm run wp-env start -- --xdebug=develop,debug,profile
How to 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.