[wp-trac] [WordPress Trac] #57814: Use `wp_theme_has_theme_json` in `_wp_theme_json_webfonts_handler`

WordPress Trac noreply at wordpress.org
Mon Mar 13 19:01:28 UTC 2023


#57814: Use `wp_theme_has_theme_json` in `_wp_theme_json_webfonts_handler`
---------------------------+------------------------------
 Reporter:  spacedmonkey   |       Owner:  (none)
     Type:  defect (bug)   |      Status:  new
 Priority:  normal         |   Milestone:  Awaiting Review
Component:  Script Loader  |     Version:  6.0
 Severity:  normal         |  Resolution:
 Keywords:  has-patch      |     Focuses:  performance
---------------------------+------------------------------

Comment (by flixos90):

 Replying to [comment:12 spacedmonkey]:
 > The expensive part of `_wp_theme_json_webfonts_handler`, is the call to
 `WP_Theme_JSON_Resolver::get_merged_data()`. If this is not called here,
 is called later in `wp_get_global_settings` / `wp_enqueue_global_styles`.
 If we can workout caching, `wp_get_global_settings` persistently then that
 could solve this problem. We are just moving that piece of heavy compute
 later in the process of the page.

 I see. Makes sense then that we're basically just deferring the call to a
 later point in time, which looks like `wp-template` becomes slower, but
 it's roughly the same amount that `wp-before-template` becomes faster. So
 that's expected then.

 > Here is a simplier fix at https://github.com/WordPress/wordpress-
 develop/pull/4218.
 >
 > This just load theme.json data and not all other data. This seems to fix
 the issue.

 I ran another test for your new PR (see
 [https://docs.google.com/spreadsheets/d/1Oe-6ZO_Jqt6qSp2yF-
 ohb05McEB2y22aqU0S7gXuyGs/edit#gid=1374089908 this sheet]), and it really
 doesn't make a difference. Your new fix improves `wp-before-template` by
 ~1ms and reduces `wp-template` by ~1ms, while the previous PR did the same
 by ~4ms for both metrics - eventually the outcome for total load time is
 similar: **Both PRs bring a win of ~0.5ms (almost 1%).**

 I think your original fix from https://github.com/WordPress/wordpress-
 develop/pull/4185 is much simpler and less error-prone, so I would prefer
 committing that one. The other fix requires a much closer attention and
 better understanding of the theme.json parsing logic.

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


More information about the wp-trac mailing list