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

Improve _get_block_templates_paths performace #5281

Closed

Conversation

kt-12
Copy link
Member

@kt-12 kt-12 commented Sep 22, 2023

Trac ticket: https://core.trac.wordpress.org/ticket/58196


This Pull Request is for code review only. Please keep all other discussion 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
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.

Nice idea! I'm not seeing a big performance difference in the automated Performance Test run, but that's likely due to this issue not really effecting the TT3 theme that the block-theme tests are based on.

I see that all of the unit tests are currently failing, and that's likely due to the removal of the file_exists check. I wonder if wrapping that code in a try/catch block will fix those tests.

Let's get some benchmarking on this change, but seems sensible. We may even want to consider caching this persistently in the future.

@kt-12 kt-12 marked this pull request as ready for review November 28, 2023 11:47
@kt-12 kt-12 changed the title [Draft] Improve _get_block_templates_paths performace Improve _get_block_templates_paths performace Nov 28, 2023
@kt-12
Copy link
Member Author

kt-12 commented Nov 28, 2023

TT4 Homepage performance metrics. Conducted 500 rounds 3 times and got the mean. This is a bit contradictory to what was observed in Blackfire.

Title PR Mean Trunk Mean
Response Time (mean) 412.69 411.71
wp-load-alloptions-query (mean) 3.36 3.37
wp-before-template (mean) 161.00 160.86
wp-before-template-db-queries (mean) 0.00 0.00

@joemcgill
Copy link
Member

360effb Fixes the test failures and I've run some benchmarks locally which do show some small potential improvement, but not huge. Likely due to most of the performance impact being incurred the first time the function is called.

However, there is a decent memory improvement by avoiding redundant calls to the Iterator class methods. Not opposed to committing this enhancement, but I do think focusing on the parent function, _get_block_templates_files would have a bigger impact than this change.

Trunk
Screenshot 2023-12-01 at 3 25 10 PM

w/ PR applied
Screenshot 2023-12-01 at 3 25 00 PM

Copy link
Member

@felixarntz felixarntz left a comment

Choose a reason for hiding this comment

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

@kt-12 While the performance gain here is very small, I think the enhancement is simple enough to go for it, plus there's the memory usage benefit.

Since there are no tests for _get_block_template_paths(), could you add some basic coverage? Probably simply two tests are enough, one for a directory that exists, another one for a directory that doesn't exist.

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 for adding tests. Couple of nits, but this is looking good.

tests/phpunit/tests/blocks/getBlockTemplates.php Outdated Show resolved Hide resolved
tests/phpunit/tests/blocks/getBlockTemplates.php Outdated Show resolved Hide resolved
tests/phpunit/tests/blocks/getBlockTemplates.php Outdated Show resolved Hide resolved
Copy link
Member

@mukeshpanchal27 mukeshpanchal27 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 for the PR. Left some feedback for your consideration.

src/wp-includes/block-template-utils.php Outdated Show resolved Hide resolved
tests/phpunit/tests/blocks/getBlockTemplates.php Outdated Show resolved Hide resolved
tests/phpunit/tests/blocks/getBlockTemplates.php Outdated Show resolved Hide resolved
tests/phpunit/tests/blocks/getBlockTemplates.php Outdated Show resolved Hide resolved
tests/phpunit/tests/blocks/getBlockTemplates.php Outdated Show resolved Hide resolved
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. The updates all look good to me.

Copy link
Member

@mukeshpanchal27 mukeshpanchal27 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, for the changes; they look good to me.

Remove extra line

Co-authored-by: Mukesh Panchal <mukeshpanchal27@users.noreply.github.com>
@joemcgill
Copy link
Member

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