[wp-trac] [WordPress Trac] #56666: Bug/performance: No need to make repeat calls to `get_theme_file_path` in `register_block_style_handle`

WordPress Trac noreply at wordpress.org
Tue Sep 27 15:09:28 UTC 2022


#56666: Bug/performance: No need to make repeat calls to `get_theme_file_path` in
`register_block_style_handle`
--------------------------+-----------------------------
 Reporter:  aristath      |       Owner:  SergeyBiryukov
     Type:  defect (bug)  |      Status:  closed
 Priority:  normal        |   Milestone:  6.1
Component:  General       |     Version:  trunk
 Severity:  normal        |  Resolution:  fixed
 Keywords:  has-patch     |     Focuses:  performance
--------------------------+-----------------------------
Changes (by SergeyBiryukov):

 * owner:  (none) => SergeyBiryukov
 * status:  new => closed
 * resolution:   => fixed


Comment:

 In [changeset:"54327" 54327]:
 {{{
 #!CommitTicketReference repository="" revision="54327"
 Blocks: Remove extra `get_theme_file_path()` calls in
 `register_block_style_handle()`.

 The `register_block_style_handle()` function runs ~200 times on each page
 load. Each time it runs, we call `get_theme_file_path()` and then run it
 through `wp_normalize_path()`.

 `get_theme_file_path()` calls a few other functions:
 `get_stylesheet_directory()`, `get_stylesheet()`, `get_option()`, and
 there's a bunch of filters that run on each iteration of that, without
 ever changing.

 By caching the value in a static variable, we can avoid ~200 calls on many
 functions and filters, improving performance.

 Follow-up to [53091], [54290], [54291], [54309].

 Props aristath, mukesh27.
 Fixes #56666.
 }}}

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


More information about the wp-trac mailing list