#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 |
|---|---|---|---|
| Priority: | normal | Milestone: | 6.1 |
| Component: | Themes | Version: | 6.1 |
| Severity: | normal | Keywords: | has-patch |
| Cc: | Focuses: | performance |
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.
4 years ago
#1
- Keywords has-patch added
SergeyBiryukov commented on PR #3410:
4 years ago
#4
Thanks for the PR! Merged in r54398.
4 years ago
#5
I'm honestly surprised that array_merge() being called in a loop (😱) wasn't the culprit...
4 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".
![(please configure the [header_logo] section in trac.ini)](/chrome/site/your_project_logo.png)
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_slugsis 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_slugsmethod reveals thatarray_map()is the call that slows it down:This PR replaces
array_mapwith a simpleforeachloop. 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