Create parsed PHP version of core's theme.json
at build time rather than during runtime
#45616
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
What problem does this address?
See https://core.trac.wordpress.org/ticket/56945 and WordPress/wordpress-develop#3536 (comment):
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 atheme.json
, parsing WordPress core'stheme.json
is an unnecessary overhead.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'stheme.json
, however given that no othertheme.json
needs to be parsed in that context, there would be a notable performance win (e.g. ~28% fasterwp_head
execution) from not even having to parse anytheme.json
file at runtime.What is your proposed solution?
theme.json
during runtime in PHP, it should be parsed into a ready-to-usetheme-json.php
file as part of the Gutenberg / WP core build process.theme.json
, including the relevant strings (based ontheme-i18n.json
) being wrapped in_x()
calls.require
that PHP file rather than having to run the expensive logic to parsetheme.json
over and over again.theme.json
during development, logic could be provided to still use the originaltheme.json
decoding logic e.g. ifWP_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 usingvar_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 parsedtheme-json.php
for their own theme, so that the performance issue can be addressed more holistically.The text was updated successfully, but these errors were encountered: