Make WordPress Core

#58384 closed enhancement (duplicate)

locate_template calls file_exists a lot

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

Description

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 (2)

#1 @costdev
14 months 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.
Reference

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?

#2 @spacedmonkey
11 months ago

  • Milestone Future Release deleted
  • Resolution set to duplicate
  • Status changed from new to closed

Duplicate of #58576.

Note: See TracTickets for help on using tickets.