Skip to content
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

Global styles: cache post-processed style variations #6857

Open
wants to merge 1 commit into
base: trunk
Choose a base branch
from

Conversation

oandregal
Copy link
Member

@oandregal oandregal commented Jun 19, 2024

Trac ticket https://core.trac.wordpress.org/ticket/61451
Follow-up to #6843
Backports WordPress/gutenberg#62610

What

This PR caches the post-processed style variation files (theme.json within the styles/ folder).

Why

To improve performance, so we don't have to process them more than once.

How

Introduces a static $style_variations_cache variable.

Test

How to test

  1. Verify the theme style variations are working as expected.

Go to "Site Editor > Styles" and apply one of them. Verify the changes are reflected in the front end. Do the same from the global styles sidebar in the site editor.

  1. Verify the block style variations defined via theme.json are working as expected.

Create a partial.json file within the styles/ folder with the following contents:

{
        "$schema": "https://schemas.wp.org/trunk/theme.json",
        "version": 2,
        "title": "Partial",
        "blockTypes": [ "core/group" ],
        "styles": {
                "color": {
                        "background": "aliceblue"
                }
        }
}

Go to any editor, add a group block, and verify there is a "Partial" style variation (Block Settings > Styles). Apply the variation and save the changes. Verify the contents are the expected (background color is aliceblue) — also in the front-end.

Commit

Proposal for commit message, to make it easier for committers:

Global styles: cache post-processed style variations.

Props aaronrobertshaw, ramonopoly, oandregal.
See #61451.

@oandregal oandregal requested a review from joemcgill June 19, 2024 08:23
Copy link

github-actions bot commented Jun 19, 2024

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 props-bot label.

Core Committers: Use this line as a base for the props when committing in SVN:

Props oandregal, joemcgill.

To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook.

Copy link

Test using WordPress Playground

The 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

  • The Plugin and Theme Directories cannot be accessed within Playground.
  • All changes will be lost when closing a tab with a Playground instance.
  • All changes will be lost when refreshing the page.
  • A fresh instance is created each time the link below is clicked.
  • Every time this pull request is updated, a new ZIP file containing all changes is created. If changes are not reflected in the Playground instance,
    it's possible that the most recent build failed, or has not completed. Check the list of workflow runs to be sure.

For more details about these limitations and more, check out the Limitations page in the WordPress Playground documentation.

Test this pull request with WordPress Playground.

@oandregal
Copy link
Member Author

@joemcgill what are your thoughts on doing this?

I was looking at the performance results for #6843 (cache reading the contents from the filesystem), and I'm a bit confused.

I'm not familiar with what we are testing for the "Admin" test, so I don't know if it should have been impacted. However, for the "Front End › Theme: twentytwentyfour" I would have expected to be more impacted. Instead, I see timid or conflicting results:

  • wpMemory: increased, which makes sense given we now cache those files.
  • wpTotal: it has been reduced minimally and increased (also minimally) in others.
  • timeToFirstByte: increased minimally
Captura de ecrã 2024-06-19, às 10 31 57

The results for this PR are similarly confusing:

  • wpMemory: increased, as expected.
  • wpTotal & timeToFirstByte are both higher (I'd expect the contrary).
Captura de ecrã 2024-06-19, às 10 37 36

This is my current understanding of the new feature:

  • In the front-end, we may or may not need to enqueue new styles related to block style variations defined by the theme.
  • This requires inspecting all the files within styles/ which is done in the get_style_variations method at some point.

Unless the tests are not triggering the file reads from the filesystem for some reason, I'd have expected the numbers to have improved with the cache (previous PR & this one).

@joemcgill
Copy link
Member

In theory, adding a cache here should be more performant. However, it seem that the refactor of WP_Theme_JSON_Resolver::get_style_variations has also added a lot more processing to that method, and the cache (if it's even being used) is not offsetting the additional processing.

Trunk
image

This PR
image

It seems odd to me that in trunk, none of the WP_Theme_JSON construction calls were actually running. I've investigated this by setting a breakpoint in this method to see the code execution via XDebug, and it seems like in each of the 4 times this method is called on the TT4 homepage, it's always passing 'block' as the scope, but all of the variations are from the 'theme' scope, so in trunk this is all being skipped and is returning an empty array, whereas now this PR is just checking to see whether there is a scope at all, not just that it matches the scope being passed to the method.

This seems like a likely bug.

@oandregal
Copy link
Member Author

oandregal commented Jun 20, 2024

This seems like a likely bug.

As far as I tested, the feature is working correctly in trunk (instructions, though I did more random things as well). I also tested the related one (theme style variations).

I haven't had the time to look at this using xdebug today, as I was investigating a proof of concept to optimize the data flow.

@joemcgill
Copy link
Member

Thanks, I'll do some more testing. I'm just surprised that currently no variations are being processed while running TT4 in trunk, but perhaps it's because those code paths aren't being triggered without adding some variations manually?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
2 participants