[wp-trac] [WordPress Trac] #59969: Conditional loading `build_template_part_block_variations` for performance improvement

WordPress Trac noreply at wordpress.org
Mon Nov 27 16:27:02 UTC 2023


#59969: Conditional loading `build_template_part_block_variations` for performance
improvement
--------------------------+-----------------------------
 Reporter:  thekt12       |      Owner:  (none)
     Type:  defect (bug)  |     Status:  new
 Priority:  normal        |  Milestone:  Awaiting Review
Component:  General       |    Version:
 Severity:  normal        |   Keywords:  needs-patch
  Focuses:  performance   |
--------------------------+-----------------------------
 Raised in [https://github.com/WordPress/gutenberg/issues/45601 Lazy
 initialization of block variants].


 Profiling of if TT4 homepage showed `register_block_core_template_part`
 accounts for ~7% of load time ~80ms. The function calls
 `build_template_part_block_variations`, which accounts for 99% of the
 function time. This function is called in almost every page. The root
 reason for this is deep down in the call stack, it calls
 `WP_Theme_JSON_Resolver::get_merged_data`, which calls
 `WP_Theme_JSON::__construct` for parsing theme JSON.

 The core issue of improving JSON loading will be addressed in another
 [https://github.com/WordPress/performance/issues/746 Improve template
 loading and rendering] activity.

 However, it was found that by disabling
 `build_template_part_block_variations`, for pages that don’t require it,
 we found there is an improvement of ~80ms which aligns with the total time
 needed for `register_block_core_template_part`.
 Disabling change that was made - [
 https://github.com/WordPress/gutenberg/issues/45601#issuecomment-1516214955
 WordPress/gutenberg#45601] (comment) tested on the default homepage of TT4
 Before Change -
 https://blackfire.io/profiles/933e16a5-0932-41e3-8fb7-a21c10dc3811/graph
 After Change- https://blackfire.io/profiles/c225c202-974c-4a9c-886f-
 ef731273461c/graph.

 By removing the call to `build_template_part_block_variations` on pages
 that don't have variation could improve the performance.

-- 
Ticket URL: <https://core.trac.wordpress.org/ticket/59969>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform


More information about the wp-trac mailing list