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

Create parsed PHP version of core's theme.json at build time rather than during runtime #45616

Open
felixarntz opened this issue Nov 8, 2022 · 2 comments · May be fixed by WordPress/wordpress-develop#4641
Assignees
Labels
[Feature] Site Editor Related to the overarching Site Editor (formerly "full site editing") [Type] Enhancement A suggestion for improvement. [Type] Performance Related to performance efforts

Comments

@felixarntz
Copy link
Member

felixarntz commented Nov 8, 2022

What problem does this address?

See https://core.trac.wordpress.org/ticket/56945 and WordPress/wordpress-develop#3536 (comment):

  • Parsing theme.json is a rather expensive process. Despite ongoing optimization efforts (e.g. https://core.trac.wordpress.org/ticket/56974), this can only get us so far. Especially for classic themes that do not even provide a theme.json, parsing WordPress core's theme.json is an unnecessary overhead.
  • As discussed in Fix wp_head performance regression for classic themes wordpress-develop#3536, for classic themes it is still necessary to use some of the data from core's theme.json, however given that no other theme.json needs to be parsed in that context, there would be a notable performance win (e.g. ~28% faster wp_head execution) from not even having to parse any theme.json file at runtime.

What is your proposed solution?

  • Instead of parsing the built-in theme.json during runtime in PHP, it should be parsed into a ready-to-use theme-json.php file as part of the Gutenberg / WP core build process.
  • The build process should render a PHP file returning an array with all the data from theme.json, including the relevant strings (based on theme-i18n.json) being wrapped in _x() calls.
  • This way, Gutenberg and WordPress core can simply require that PHP file rather than having to run the expensive logic to parse theme.json over and over again.
    • Potentially, to simplify working with theme.json during development, logic could be provided to still use the original theme.json decoding logic e.g. if WP_DEBUG is enabled or something like that.

This idea originally was proposed in WordPress/wordpress-develop#3536, but was then moved out of there so that the rest of the PR could be merged to make it into the WordPress 6.1.1 release. A previous version of the PR includes an example for that theme-json.php file (manually created using var_export(), please ignore the WPCS violations in there) - I'm linking this here just for reference, of course this file would only make sense to be generated automatically for a reasonable implementation, as proposed above.

Potentially, we could take this even further by making the build tool to create a PHP file from theme.json available to external theme developers as well. This way, theme developers could optionally adopt that tool and provide an already parsed theme-json.php for their own theme, so that the performance issue can be addressed more holistically.

@felixarntz felixarntz added [Type] Enhancement A suggestion for improvement. [Type] Performance Related to performance efforts [Feature] Full Site Editing labels Nov 8, 2022
@felixarntz
Copy link
Member Author

cc @oandregal @spacedmonkey

This is a follow up to WordPress/wordpress-develop#3536, in order to get the other parts of that PR merged into 6.1.1 (the proposal here will require a bit more time). I would suggest this issue to be added to #45171.

@felixarntz felixarntz added the [Feature] Block API API that allows to express the block paradigm. label Nov 8, 2022
felixarntz added a commit to felixarntz/wordpress-develop that referenced this issue Nov 8, 2022
@gziolo gziolo removed the [Feature] Block API API that allows to express the block paradigm. label Feb 27, 2023
@spacedmonkey spacedmonkey self-assigned this Mar 7, 2023
@spacedmonkey
Copy link
Member

@felixarntz @oandregal @aristath

Created a simple PR for parsing theme.json to php. See WordPress/wordpress-develop#4641

Basically a copy of this WordPress/wordpress-develop@688b88d

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[Feature] Site Editor Related to the overarching Site Editor (formerly "full site editing") [Type] Enhancement A suggestion for improvement. [Type] Performance Related to performance efforts
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants