Make WordPress Core

Changeset 54398


Ignore:
Timestamp:
10/06/2022 03:25:47 PM (4 years ago)
Author:
SergeyBiryukov
Message:

Themes: Replace array_map() usage in WP_Theme_JSON::get_default_slugs().

When loading a page on the frontend using Xdebug & Webgrind, with the Twenty Twenty-Three theme and no plugins activated, the biggest performance bottleneck currently (on the PHP side) is WP_Theme_JSON::merge(). Analysing the data a bit more, it became evident that WP_Theme_JSON::get_default_slugs() is the part of that method which takes most of the resources and time.

Further analysis of the method revealed that array_map() was the call that slowed it down.

This commit replaces the array_map() call with a simple foreach loop, improving page load speed significantly.

Follow-up to [52275], [52364].

Props aristath.
Fixes #56745.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/class-wp-theme-json.php

    r54385 r54398  
    24232423
    24242424                        $slugs_for_preset = array();
    2425                         $slugs_for_preset = array_map(
    2426                                 static function( $value ) {
    2427                                         return isset( $value['slug'] ) ? $value['slug'] : null;
    2428                                 },
    2429                                 $preset
    2430                         );
     2425                        foreach ( $preset as $item ) {
     2426                                if ( isset( $item['slug'] ) ) {
     2427                                        $slugs_for_preset[] = $item['slug'];
     2428                                }
     2429                        }
     2430
    24312431                        _wp_array_set( $slugs, $metadata['path'], $slugs_for_preset );
    24322432                }
Note: See TracChangeset for help on using the changeset viewer.