[wp-trac] [WordPress Trac] #58196: Improve performance of `_get_block_templates_paths`
WordPress Trac
noreply at wordpress.org
Tue May 2 15:04:04 UTC 2023
#58196: Improve performance of `_get_block_templates_paths`
-----------------------------------------+------------------------------
Reporter: spacedmonkey | Owner: (none)
Type: enhancement | Status: new
Priority: normal | Milestone: Awaiting Review
Component: Themes | Version: 5.9
Severity: normal | Resolution:
Keywords: has-patch reporter-feedback | Focuses: performance
-----------------------------------------+------------------------------
Comment (by spacedmonkey):
@flixos90 @joemcgill @johnbillion @oandregal
Okay, so for some context. I was doing some profiling using blackfire. On
block themes, I noticed that calls to `RecursiveDirectoryIterator` was
counting for as much as 6-8% of page load. See
[https://core.trac.wordpress.org/attachment/ticket/58196/Screenshot%202023-05-02%20at%2015.35.11.png
screenshot]. I track this down to `_get_block_templates_paths`. What
_get_block_templates_paths does, it a recursive lookup for html files in a
directory. However, as this function is not cached and is called 13 times
in TT3, this results in this expensive call being called multiple times.
In [https://github.com/WordPress/wordpress-develop/pull/4383 #4383], I
tried replacing, RecursiveDirectoryIterator with glob. But as it still
called 13 times, it is still expensive. In [https://github.com/WordPress
/wordpress-develop/pull/4397 #4397], I add caching to this function and
remove the regex ( as it not really needed ). The results are really
improves.
I run it against benchmarks ( 1000 runs ).
|| || Trunk || PR ||
||Response Time (median)||152.35||133.09||
||wp-before-template (median)||92.7||74.13||
||wp-before-template-db-queries (median)||6.71||6.62||
||wp-template (median)||53.36||52.46||
||wp-total (median)||146.49||127.32||
||wp-template-db-queries (median)||3.35||3.26||
Blackfire
[https://core.trac.wordpress.org/attachment/ticket/58196/Screenshot%202023-05-02%20at%2015.47.09.png
Before],
[https://core.trac.wordpress.org/attachment/ticket/58196/Screenshot%202023-05-02%20at%2015.48.15.png
After].
XHProf
[https://core.trac.wordpress.org/attachment/ticket/58196/Screenshot%202023-05-02%20at%2015.32.27.png
Before],
[https://core.trac.wordpress.org/attachment/ticket/58196/Screenshot%202023-05-02%20at%2015.31.56.png
After].
Query monitor
[https://core.trac.wordpress.org/attachment/ticket/58196/Screenshot%202023-05-02%20at%2015.21.38.png
Before],
[https://core.trac.wordpress.org/attachment/ticket/58196/Screenshot%202023-05-02%20at%2015.20.06.png
After].
The results speak for themselves and are well worth reviewing. Adding
caching is worth doing.
--
Ticket URL: <https://core.trac.wordpress.org/ticket/58196#comment:9>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform
More information about the wp-trac
mailing list