[wp-trac] [WordPress Trac] #58196: Improve performance of `_get_block_templates_paths`

WordPress Trac noreply at wordpress.org
Mon Nov 27 15:49:46 UTC 2023


#58196: Improve performance of `_get_block_templates_paths`
-----------------------------------------+--------------------------
 Reporter:  spacedmonkey                 |       Owner:  thekt12
     Type:  enhancement                  |      Status:  assigned
 Priority:  normal                       |   Milestone:  6.5
Component:  Themes                       |     Version:  5.9
 Severity:  normal                       |  Resolution:
 Keywords:  has-patch reporter-feedback  |     Focuses:  performance
-----------------------------------------+--------------------------

Comment (by thekt12):

 Profiled it in TT4 and found that this function is being called
 `_get_block_templates_paths()` 8 times. The function is called from
 another expensive function `_get_block_templates_files`
 [[https://core.trac.wordpress.org/attachment/ticket/58196/Screenshot%202023-11-27%20at%2015.23.20.png]]


 `_get_block_templates_files`(~102 ms) is expensive mainly due to it's
 three child ->
 `_add_block_template_part_area_info` (49 ms called 6 times),
 `_add_block_template_info` (~32ms called 7 times ) and
 `_get_block_templates_paths` (~16ms called 8 times).

 Out of the 8 calls to `_get_block_templates_paths` 7 calls are for the
 same directory. There is very little scope to improve core logic as it
 mostly uses PHP's core function to traverse files, however, introducing
 static caching ([https://github.com/WordPress/wordpress-develop/pull/5281
 PR 5281]) or persistent caching could eliminate the repetitive call to
 `_get_block_templates_paths`.

-- 
Ticket URL: <https://core.trac.wordpress.org/ticket/58196#comment:30>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform


More information about the wp-trac mailing list