Make WordPress Core

Opened 2 months ago

Last modified 5 weeks ago

#59595 assigned enhancement

Improve performance of WP_Theme_JSON::compute_style_properties

Reported by: spacedmonkey's profile spacedmonkey Owned by: pereirinha's profile pereirinha
Milestone: 6.5 Priority: normal
Severity: normal Version: 5.8
Component: Editor Keywords: has-patch
Focuses: performance Cc:

Description

When profiling WP 6.4 ( other releases ), it was not that the method WP_Theme_JSON::compute_style_properties can result in around 6-11% of server time spent to generate a page. Research should be conducted to see if this method and child function / method calls, could be improved, to improve performance of this method.

Attachments (4)

Screenshot 2023-10-24 at 22.37.16.png (1.2 MB) - added by pereirinha 6 weeks ago.
Request overview before
Screenshot 2023-10-24 at 22.38.16.png (1.1 MB) - added by pereirinha 6 weeks ago.
Function details before
Screenshot 2023-10-24 at 22.37.29.png (1.2 MB) - added by pereirinha 6 weeks ago.
Request overview after
Screenshot 2023-10-24 at 22.38.19.png (1.1 MB) - added by pereirinha 6 weeks ago.
Function details after

Change History (15)

This ticket was mentioned in Slack in #core-performance by mukeshpanchal27. View the logs.


2 months ago

This ticket was mentioned in Slack in #core-performance by pereirinha. View the logs.


8 weeks ago

This ticket was mentioned in Slack in #core-performance by pereirinha. View the logs.


7 weeks ago

@pereirinha
6 weeks ago

Request overview before

@pereirinha
6 weeks ago

Function details before

@pereirinha
6 weeks ago

Request overview after

@pereirinha
6 weeks ago

Function details after

#4 @pereirinha
6 weeks ago

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 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.

This ticket was mentioned in PR #5567 on WordPress/wordpress-develop by @pereirinha.


6 weeks ago
#5

  • Keywords has-patch added

Add object caching to improve the performance of WP_Theme_JSON::compute_style_properties when supported.

Trac ticket: 59595

This ticket was mentioned in Slack in #core-performance by pereirinha. View the logs.


6 weeks ago

#7 @mukesh27
6 weeks ago

  • Milestone changed from Future Release to 6.5
  • Owner set to pereirinha
  • Status changed from new to assigned

Assign to @pereirinha as he is actively working on it.

@mukesh27 commented on PR #5567:


6 weeks ago
#8

@pereirinha I did some benchmarking for TT4 theme home page using XHProf but i can't i can't find any improvement. Did i miss anything?

cc. @felixarntz @joemcgill

@pereirinha commented on PR #5567:


6 weeks ago
#9

@pereirinha I did some benchmarking for TT4 theme home page using XHProf but i can't i can't find any improvement. Did i miss anything?

cc. @felixarntz @joemcgill

Thanks, @mukeshpanchal27, for picking it up. Can the reason why you don't see improvements might be that you aren't using Memcached?

This ticket was mentioned in Slack in #core-performance by joemcgill. View the logs.


6 weeks ago

@mukesh27 commented on PR #5567:


5 weeks ago
#11

Thanks, @mukeshpanchal27, for picking it up. Can the reason why you don't see improvements might be that you aren't using Memcached?

I just enabled the Memcached through ENV and now i got the improvement after the changes.

https://i0.wp.com/github.com/WordPress/wordpress-develop/assets/10103365/94cc90c8-cca2-40c8-9b59-b0969ca87301

Note: See TracTickets for help on using tickets.