[wp-trac] [WordPress Trac] #64538: memoize wp_normalize_path

WordPress Trac noreply at wordpress.org
Wed Jan 21 22:43:09 UTC 2026


#64538: memoize wp_normalize_path
--------------------------+-----------------------------
 Reporter:  josephscott   |      Owner:  (none)
     Type:  defect (bug)  |     Status:  new
 Priority:  normal        |  Milestone:  Awaiting Review
Component:  General       |    Version:
 Severity:  normal        |   Keywords:
  Focuses:                |
--------------------------+-----------------------------
 I noticed that on one site `wp_normalize_path()` was being called about
 4,000 times per request.  This looks like a good place to add a simple
 static cache variable.  I have put together a small patch to make this
 happen.

 This has the added benefit of also dropping the number of calls to
 `wp_is_stream()`.  On the test request I was looking at it went from 4,190
 to 1,460.  While `wp_is_stream()` doesn't do much, when we are talking
 about ~4,000 calls even tiny amounts add up quick.  This also showed that
 adding the cache to `wp_normalize_path()` provides a pretty good hit rate
 ( hovering around 66% ).

 Extracting just those to functions and comparing the uncached vs. cached
 `wp_normalize_path()`, at 4,000 calls the time went from 1.4ms to 0.4ms (
 PHP 8.4.7 on M3 laptop ).

-- 
Ticket URL: <https://core.trac.wordpress.org/ticket/64538>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform


More information about the wp-trac mailing list