Editor: Cache merged global styles in the theme_json group - #13192
Draft
sirreal wants to merge 2 commits into
Draft
Editor: Cache merged global styles in the theme_json group#13192sirreal wants to merge 2 commits into
sirreal wants to merge 2 commits into
Conversation
`wp_get_global_styles()` is the only `theme_json` accessor without an object cache. Every call builds a fresh `WP_Theme_JSON` and merges four origins through `WP_Theme_JSON_Resolver::get_merged_data()`, at roughly 0.3ms per call. `wp_render_layout_support_flag()` worked around that cost with a function-static snapshot that nothing could invalidate, so a layout rendered after a theme change kept the previous `blockGap` value for the remaining lifetime of the PHP process. That is what forced the block style variation test to run in a separate process. Cache the merged styles in the non-persistent `theme_json` group, keyed by origin and by the `resolve-variables` transform, and clear those keys in `wp_clean_theme_json_cache()`, exactly as `wp_get_global_settings()` already does. The function-static in `wp_render_layout_support_flag()` is then unnecessary and is removed, so `switch_theme` refreshes layout styles and `@runInSeparateProcess` can be dropped from the test. `gallery.php` and `image.php` also call `wp_get_global_styles()` on every render with no cache of their own, and benefit as well. The function-static additionally ignored `wp_is_development_mode( 'theme' )`, so theme developers saw stale block gaps in layout output. The object cache respects that check. Measured on this branch, 1,000 iterations, median of five runs: wp_get_global_styles() before 311.61ms after 0.23ms wp_render_layout_support_flag() before 15.19ms after 15.73ms Trac ticket: https://core.trac.wordpress.org/ticket/65893
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. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
theme_jsoncache group, including origin and variable-resolution mode in each key.wp_clean_theme_json_cache()and bypasses them in theme development mode.Verification
git diff --checkpassed.Trac: https://core.trac.wordpress.org/ticket/65893