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

Refresh - Validate URL in Locate Template #6502

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

Conversation

shail-mehta
Copy link
Member

Added refresh patch for Validate url in locate template.

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

Copy link

github-actions bot commented May 4, 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 shailu25, jorbin, mukesh27, martinkrcho, peterwilsoncc.

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

@shail-mehta shail-mehta changed the title Validate URL in Locate Template Refresh - Validate URL in Locate Template May 4, 2024
Copy link

github-actions bot commented May 4, 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.

@shail-mehta shail-mehta force-pushed the validate-url-in-locate-template branch from d3ff41f to 8ae3447 Compare May 5, 2024 08:59
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.

This will impact the performance.

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;

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.

Suggested change
$located = $wp_template_path . '/' . $template_name;
$located = $template;

Copy link
Member Author

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.

Choose a reason for hiding this comment

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

Thanks.

Copy link

@martinkrcho martinkrcho left a 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.

Comment on lines +500 to +504
* @dataProvider data_locate_template_only_loads_theme_files
*
* @ticket 58905
*
* @covers ::locate_template
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
* @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.

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.

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.

@peterwilsoncc
Copy link
Contributor

@mukeshpanchal27 Are you able to edit the comment above to note the raw difference. As the benchmarking script is using hrtime() (nanoseconds) I think the raw numbers could be more helpful than a percentage.

@mukeshpanchal27
Copy link
Member

@peterwilsoncc Updated #6502 (review)

@peterwilsoncc
Copy link
Contributor

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.

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

Successfully merging this pull request may close these issues.

5 participants