Block Template persistent cache- transient + object cache.
Trac ticket: https://core.trac.wordpress.org/ticket/59600
Tested Performance for Memcache version on Trunk and PR - Trunk median was 114.6 and PR median was 113
I also tested the transient version on Trunk and PR but could see a downgrade of around 5 ms.
However, I am not confident about the result as I could see drastic performance fluctuation and had to do the test several rounds to get a convincing stable result.
This Pull Request is for code review only. Please keep all other discussions in the Trac ticket. Do not merge this Pull Request. See GitHub Pull Requests for Code Review in the Core Handbook for more details.
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 thekt12, joemcgill.
To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook.
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.
Thanks @kt-12. When running some profiling data on this approach, I'm not seeing much benefit to adding a cache at this point in the execution process.
Comparing runs of
_build_block_template_result_from_file()with and without this cache in place, there is a marginal improvement and seems like the need to query the DB for these transients offsets any benefit in avoiding thefile_get_contents()calls. In fact, this function is only responsible for ~1% of the overall execution time of the TT4 homepage without additional caching, so I'm not sure there is a benefit in adding caching here.
_build_block_template_result_from_file()Trunk
Current PR
get_block_templates()However, its parent function,
get_block_templates(), does seem to be present a bigger opportunity for improvement, as it's profiling at 5% of iwt for the same requests. Of that time, most of the cost seems to from_get_block_templates_files(), with most of that processing eventually happening inwp_get_theme_data_custom_templates()when theWP_Theme_JSON_Resolver::get_theme_data()parses thecustomTemplatesproperty from theWP_Theme_JSONdata provided by the theme.I think we could consider adding a cache to either `_get_block_templates_files()` or `wp_get_theme_data_custom_templates()` to have bigger impact—at least until we are able to handle some/all of https://core.trac.wordpress.org/ticket/57789.
I was investigating the performance opportunity get_block_templates() - Down the line, this function is calling WP_Theme_JSON_Resolver::get_theme_data which is the major reason for the performance.
At the moment, get_theme_data is static cached so, even if we persistent cache get_block_templates we won't get any benefit as get_theme_data is referred at two more places and the next function calling it will take the hit.


I think we could consider adding a cache to either `_get_block_templates_files()` or `wp_get_theme_data_custom_templates()` to have bigger impact—at least until we are able to handle some/all of https://core.trac.wordpress.org/ticket/57789.