From 4943dbf577b8c65b7994d979c2963d688e42f6c0 Mon Sep 17 00:00:00 2001 From: Sergey Biryukov Date: Thu, 6 Oct 2022 15:27:13 +0000 Subject: [PATCH] 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. Built from https://develop.svn.wordpress.org/trunk@54398 git-svn-id: http://core.svn.wordpress.org/trunk@53957 1a063a9b-81f0-0310-95a4-ce76da25c4cd --- wp-includes/class-wp-theme-json.php | 12 ++++++------ wp-includes/version.php | 2 +- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/wp-includes/class-wp-theme-json.php b/wp-includes/class-wp-theme-json.php index 1774c5ef6f..40262661e4 100644 --- a/wp-includes/class-wp-theme-json.php +++ b/wp-includes/class-wp-theme-json.php @@ -2422,12 +2422,12 @@ class WP_Theme_JSON { } $slugs_for_preset = array(); - $slugs_for_preset = array_map( - static function( $value ) { - return isset( $value['slug'] ) ? $value['slug'] : null; - }, - $preset - ); + foreach ( $preset as $item ) { + if ( isset( $item['slug'] ) ) { + $slugs_for_preset[] = $item['slug']; + } + } + _wp_array_set( $slugs, $metadata['path'], $slugs_for_preset ); } diff --git a/wp-includes/version.php b/wp-includes/version.php index e154003dc4..06c45e045a 100644 --- a/wp-includes/version.php +++ b/wp-includes/version.php @@ -16,7 +16,7 @@ * * @global string $wp_version */ -$wp_version = '6.1-beta3-54397'; +$wp_version = '6.1-beta3-54398'; /** * Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.