-
Notifications
You must be signed in to change notification settings - Fork 2.6k
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
Refresh - Validate URL in Locate Template #6502
base: trunk
Are you sure you want to change the base?
Refresh - Validate URL in Locate Template #6502
Conversation
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 Core Committers: Use this line as a base for the props when committing in SVN:
To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook. |
Test using WordPress PlaygroundThe 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
For more details about these limitations and more, check out the Limitations page in the WordPress Playground documentation. |
d3ff41f
to
8ae3447
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This will impact the performance.
src/wp-includes/template.php
Outdated
break; | ||
} elseif ( $is_child_theme && file_exists( $wp_template_path . '/' . $template_name ) ) { | ||
} elseif ( $is_child_theme && file_exists( $template ) && 0 === validate_file( $template ) ) { | ||
$located = $wp_template_path . '/' . $template_name; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This could be simplified a bit.
$located = $wp_template_path . '/' . $template_name; | |
$located = $template; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@martinkrcho Thanks for the feedback. I have added suggested changes in latest commit.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just a small suggestion.
…alidate-url-in-locate-template
…alidate-url-in-locate-template
…alidate-url-in-locate-template
* @dataProvider data_locate_template_only_loads_theme_files | ||
* | ||
* @ticket 58905 | ||
* | ||
* @covers ::locate_template |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
* @dataProvider data_locate_template_only_loads_theme_files | |
* | |
* @ticket 58905 | |
* | |
* @covers ::locate_template | |
* @ticket 58905 | |
* | |
* @covers ::locate_template | |
* | |
* @dataProvider data_locate_template_only_loads_theme_files |
Correct the annotation order.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I did some benchmark for script execution over 1,000 iterations. Overall, the new_locate_template()
function shows a performance decrease ranging from 29.5% to 109.7% compared to the locate_template()
function in most cases.
Benchmark result: Average time spent for 1 x 1000 iterations
locate_template() - 2327291, new_locate_template() - 3371709, Difference: 1044418, Change: 44.9%
locate_template() - 4217750, new_locate_template() - 5885542, Difference: 1667792, Change: 39.5%
locate_template() - 2649750, new_locate_template() - 3660833, Difference: 1011083, Change: 38.2%
locate_template() - 4466125, new_locate_template() - 5970000, Difference: 1503875, Change: 33.7%
locate_template() - 2321167, new_locate_template() - 4868625, Difference: 2547458, Change: 109.7%
locate_template() - 3231500, new_locate_template() - 4728166, Difference: 1496666, Change: 46.3%
locate_template() - 2417042, new_locate_template() - 3442250, Difference: 1025208, Change: 42.4%
locate_template() - 3219166, new_locate_template() - 4169375, Difference: 950209, Change: 29.5%
locate_template() - 2725250, new_locate_template() - 3653625, Difference: 928375, Change: 34.1%
locate_template() - 2405292, new_locate_template() - 3170375, Difference: 765083, Change: 31.8%
locate_template() - 2573292, new_locate_template() - 3570792, Difference: 997500, Change: 38.8%
locate_template() - 2514834, new_locate_template() - 3419583, Difference: 904749, Change: 36%
locate_template() - 5061292, new_locate_template() - 3319542, Difference: -1741750, Change: -34.4%
locate_template() - 2762333, new_locate_template() - 4013458, Difference: 1251125, Change: 45.3%
locate_template() - 2581125, new_locate_template() - 3664292, Difference: 1083167, Change: 42%
locate_template() - 2170583, new_locate_template() - 3384125, Difference: 1213542, Change: 55.9%
locate_template() - 2738209, new_locate_template() - 3909125, Difference: 1170916, Change: 42.8%
locate_template() - 2437917, new_locate_template() - 4095667, Difference: 1657750, Change: 68%
locate_template() - 3242500, new_locate_template() - 4309958, Difference: 1067458, Change: 32.9%
locate_template() - 4649834, new_locate_template() - 6784333, Difference: 2134499, Change: 45.9%
locate_template() - 2123125, new_locate_template() - 3151250, Difference: 1028125, Change: 48.4%
locate_template() - 2147125, new_locate_template() - 3126417, Difference: 979292, Change: 45.6%
locate_template() - 2574291, new_locate_template() - 3646625, Difference: 1072334, Change: 41.7%
locate_template() - 2506208, new_locate_template() - 3698250, Difference: 1192042, Change: 47.6%
Note: To run the benchmark, I use the Twenty Twenty-One
theme and make duplicate templates from existing ones so it will not used cached version.
@mukeshpanchal27 Are you able to edit the comment above to note the raw difference. As the benchmarking script is using |
@peterwilsoncc Updated #6502 (review) |
Converting the raw times from nanoseconds to milliseconds is showing a showdown of between 0.7ms to 2.5ms over 1000 iterations so I don't think it's worth considering the performance impacts as a reason to block the benefits of avoiding using the function to include files outside of the template paths. |
Added refresh patch for Validate url in locate template.
Trac ticket: https://core.trac.wordpress.org/ticket/58905