Make WordPress Core

Opened 2 weeks ago

Last modified 2 weeks ago

#58384 new enhancement

locate_template calls file_exists a lot

Reported by: spacedmonkey's profile spacedmonkey Owned by:
Milestone: Future Release Priority: high
Severity: normal Version: 4.7
Component: Themes Keywords:
Focuses: performance Cc:


The function locate_template calls file_exists three times for every each template name. As locate_template can be called multiple times on a page request for both classic and block themes, this can result in poor performance for this function.

As file_exists can be an expensive function to run, as the file lookup on file system can be slow, some level of caching should be added to this function.

Change History (1)

#1 @costdev
2 weeks ago

Thanks for opening this ticket @spacedmonkey! Worth looking into for sure.

file_exists results are cached by PHP:

Note: The results of this function are cached. See clearstatcache() for more details.

So while this reduces the impact of filesystem calls, having a cache for the results of the foreach() loop may be useful here.

Have you run any tests to see how much of a performance improvement a cache of these results brings?

Note: See TracTickets for help on using tickets.