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

Block Template persistent cache- transient + object cache. #6369

Open
wants to merge 3 commits into
base: trunk
Choose a base branch
from

Conversation

kt-12
Copy link
Member

@kt-12 kt-12 commented Apr 8, 2024

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.

Copy link

github-actions bot commented Apr 8, 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 thekt12, joemcgill.

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

Copy link

github-actions bot commented Apr 8, 2024

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.

Copy link
Member

@joemcgill joemcgill left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 the file_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
XHGUI results for trunk

Current PR
XHGUI results for the 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 in wp_get_theme_data_custom_templates() when the WP_Theme_JSON_Resolver::get_theme_data() parses the customTemplates property from the WP_Theme_JSON data provided by the theme.

image

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.

@kt-12
Copy link
Member Author

kt-12 commented Apr 22, 2024

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 the file_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 XHGUI results for trunk

Current PR XHGUI results for the 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 in wp_get_theme_data_custom_templates() when the WP_Theme_JSON_Resolver::get_theme_data() parses the customTemplates property from the WP_Theme_JSON data provided by the theme.

image 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.

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