#56745 closed defect (bug) (fixed)
Performance/Bug: calling array_map repeatedly inside WP_Theme_JSON::get_default_slugs is a bottleneck for page-loads.
Reported by: | aristath | Owned by: | SergeyBiryukov |
---|---|---|---|
Milestone: | 6.1 | Priority: | normal |
Severity: | normal | Version: | 6.1 |
Component: | Themes | Keywords: | has-patch |
Focuses: | performance | Cc: |
Description
Issue discovered when running profiling using Xdebug & webgrind. Replacing the array_map
call with a simple foreach
loop improves the page-load speed significantly.
More info in the PR below.
Change History (8)
This ticket was mentioned in PR #3410 on WordPress/wordpress-develop by aristath.
2 years ago
#1
- Keywords has-patch added
#3
@
2 years ago
- Owner set to SergeyBiryukov
- Resolution set to fixed
- Status changed from new to closed
In 54398:
SergeyBiryukov commented on PR #3410:
2 years ago
#4
Thanks for the PR! Merged in r54398.
2 years ago
#5
I'm honestly surprised that array_merge()
being called in a loop (😱) wasn't the culprit...
2 years ago
#6
I'm honestly surprised that
array_merge()
being called in a loop (😱) wasn't the culprit...
The WP_Theme_JSON->merge
call is still the most expensive call during a page-load. We'll definitely need to refactor some things there, I'll keep looking for ways to optimize that code 😅
I agree though, all those expensive function calls inside loops (and sometimes deep-nested loops of a loop of a loop) are... "less than ideal".
When loading a page on the frontend, the biggest performance bottleneck right now (on the PHP side) is
WP_Theme_JSON->merge
. Analysing the data a bit more, it becomes evident thatWP_Theme_JSON::get_default_slugs
is the part of that function that takes most of the resources and time (see screenshot below)Further analysis of the
WP_Theme_JSON::get_default_slugs
method reveals thatarray_map()
is the call that slows it down:This PR replaces
array_map
with a simpleforeach
loop. The end result is the same, and processing happens a lot faster:Notes:
Screenshots above shown with
%
values. So overall this changes makes each page-load ~1% faster.In all tests, the actual page-load was reduced from ~6300ms to ~5900
Tests were performed on a new WP installation with no plugins activated, using the twentytwentythree theme.
Reports generated using Xdebug & webgrind.
Trac ticket: https://core.trac.wordpress.org/ticket/56745