[wp-trac] [WordPress Trac] #59595: Improve performance of WP_Theme_JSON::compute_style_properties

WordPress Trac noreply at wordpress.org
Tue Oct 24 22:04:13 UTC 2023


#59595: Improve performance of WP_Theme_JSON::compute_style_properties
--------------------------+-----------------------------
 Reporter:  spacedmonkey  |       Owner:  (none)
     Type:  enhancement   |      Status:  new
 Priority:  normal        |   Milestone:  Future Release
Component:  Editor        |     Version:  5.8
 Severity:  normal        |  Resolution:
 Keywords:                |     Focuses:  performance
--------------------------+-----------------------------

Comment (by pereirinha):

 I tested using WordPress `6.5-alpha-56966-src` with the TTF theme while
 visiting an archive page with 10 posts. I can replicate similar results
 with other versions and themes and am happy to share the results if found
 relevant. For profiling, I used
 [https://make.wordpress.org/performance/handbook/measuring-performance
 /profiling-php-performance-with-xhprof/ XHProf] after an unsuccessful
 attempt to use Blackfire.

 These are the results of the tests I made and the findings.

 Though the `compute_style_properties` method is static, I didn't find a
 case where the arguments would be the same to benefit the runtime.

 In my testing, the number of calls for this method averaged 85 calls per
 request.

 The description of the method in its docblock states that:
 > Given a styles array, it extracts the style properties and adds them to
 the $declarations array…

 In a single request, the cumulative size of its arguments is:
 - Styles: 23.725 KB,
 - Settings: 803.350 KB,
 - Properties: 202.456 KB,
 - Theme Json: 1.748 MB,
 - Selector: 2.634 KB
 - Iterations: 85

 Responsible for about 50% of the wall time for this method is the child
 function `str_starts_with`, followed by
 `WP_Theme_JSON::get_property_value` with about 33.5%.

 Most of the time is spent with PHP's natural functions, which pull data
 out of large datasets, so it can't be optimized much across the board.
 However, I gave it a go with object caching, and the benefits are
 considerable for those who can leverage this feature.

 Attached are the print screens from the tests conducted. The before is as
 core, and the after runs a warm cache.

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


More information about the wp-trac mailing list