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 Unlinked AccountsThe following contributors have not linked their GitHub and WordPress.org accounts: @weston.ruter@git.wordpress.org. Contributors, please read how to link your accounts to ensure your work is properly credited in WordPress releases. 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. |
…josephscott/wordpress-develop into 64538/memoize-wp-normalize-path
There was a problem hiding this comment.
Pull request overview
This pull request adds memoization to the wp_normalize_path() function to improve performance by caching normalized path results. The implementation uses a two-tier cache system (hot and warm) to balance memory usage and cache hit rates.
Changes:
- Added memoization logic with a two-tier cache (hot/warm) limited to approximately 200 entries maximum
- Added test coverage for edge cases (empty strings, integers, stringable objects)
- Added tests to verify cache consistency across multiple calls
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 5 comments.
| File | Description |
|---|---|
| src/wp-includes/functions.php | Implements two-tier memoization cache for wp_normalize_path function with automatic rotation when cache exceeds 100 entries |
| tests/phpunit/tests/functions.php | Adds edge case tests for empty strings and integers, plus tests for stringable object handling and cache consistency |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
This also makes sure that the hot segment is reset once it hits the max instead of waiting for it to go over.
|
I worked with Opus to address the issues brought up by Copilot. |
dmsnell
left a comment
There was a problem hiding this comment.
thanks for your continued work on this @josephscott — it seems more-than-justified to take this approach, so I have left some comments relating to the actual implementation.
is the idea behind the hot/warm cache here mostly to get frequently-used paths cached while leaving some room for most-recently-used items to also be in the cache? a balance between long-term frequency and bursts of the same path? I would love to see a brief explanation of why this was chosen.
tests/phpunit/tests/functions.php
Outdated
| public function __toString() { | ||
| return '/var/www/html\\test'; | ||
| } | ||
| }; |
There was a problem hiding this comment.
a more representative test might be an SplFileInfo instance, since that is actually used in Core. as discovered in #10781 we can fix that currently-improper call in another patch.
There was a problem hiding this comment.
I have no particular preference there. I will update the test_wp_normalize_path_with_stringable_object() to try that out.
dmsnell
left a comment
There was a problem hiding this comment.
Thanks @josephscott for all the work you put into this!
`wp_normalize_path()` is called thousands of times on a given request. This patch adds memoization via a function-local static variable. This reduces the call count to the underlying `wp_is_stream()` function, and measured in testing around a 66% cache hit rate. In testing, for a site making 4000 calls to `wp_normalize_path()`, this patch led to a reduction in runtime from 1.4 ms to 0.4 ms on the test computer. While small, this time occurs early in the hotpath of the loading WordPress. Developed in: #10770 Discussed in: https://core.trac.wordpress.org/ticket/64538 Props dmsnell, josephscott, mreishus, westonruter. Fixes #64538. git-svn-id: https://develop.svn.wordpress.org/trunk@61857 602fd350-edb4-49c9-b593-d223f7449a82
`wp_normalize_path()` is called thousands of times on a given request. This patch adds memoization via a function-local static variable. This reduces the call count to the underlying `wp_is_stream()` function, and measured in testing around a 66% cache hit rate. In testing, for a site making 4000 calls to `wp_normalize_path()`, this patch led to a reduction in runtime from 1.4 ms to 0.4 ms on the test computer. While small, this time occurs early in the hotpath of the loading WordPress. Developed in: WordPress/wordpress-develop#10770 Discussed in: https://core.trac.wordpress.org/ticket/64538 Props dmsnell, josephscott, mreishus, westonruter. Fixes #64538. Built from https://develop.svn.wordpress.org/trunk@61857 git-svn-id: http://core.svn.wordpress.org/trunk@61144 1a063a9b-81f0-0310-95a4-ce76da25c4cd
https://core.trac.wordpress.org/ticket/64538
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.