From abee3f00a1011cf7550840bc2e8786928a625723 Mon Sep 17 00:00:00 2001 From: spacedmonkey Date: Wed, 7 Jun 2023 06:56:19 +0000 Subject: [PATCH] Script Loader: Improve performance of wp_maybe_inline_styles function. The `wp_maybe_inline_styles` function is called twice on the average page load. On it's second run however, it did not check to see if the style had already been processed on the first run. This resulted in calling `filesize` and `get_file_contents` unnecessarily, which was bad for performance. Now, the loop around the queued styles, checks to see if the source is set to false, meaning it has already been processed. This change also replaces calls to `filesize` with the core function `wp_filesize`, which improves extensibility. Props spacedmonkey, flixos90, peterwilsoncc, joemcgill. Fixes #58394. Built from https://develop.svn.wordpress.org/trunk@55888 git-svn-id: http://core.svn.wordpress.org/trunk@55400 1a063a9b-81f0-0310-95a4-ce76da25c4cd --- wp-includes/script-loader.php | 14 ++++++++++---- wp-includes/version.php | 2 +- 2 files changed, 11 insertions(+), 5 deletions(-) diff --git a/wp-includes/script-loader.php b/wp-includes/script-loader.php index 0ea531824b..713a0d3118 100644 --- a/wp-includes/script-loader.php +++ b/wp-includes/script-loader.php @@ -2872,12 +2872,18 @@ function wp_maybe_inline_styles() { // Build an array of styles that have a path defined. foreach ( $wp_styles->queue as $handle ) { - if ( wp_styles()->get_data( $handle, 'path' ) && file_exists( $wp_styles->registered[ $handle ]->extra['path'] ) ) { + $src = $wp_styles->registered[ $handle ]->src; + $path = wp_styles()->get_data( $handle, 'path' ); + if ( $path && $src ) { + $size = wp_filesize( $path ); + if ( ! $size ) { + continue; + } $styles[] = array( 'handle' => $handle, - 'src' => $wp_styles->registered[ $handle ]->src, - 'path' => $wp_styles->registered[ $handle ]->extra['path'], - 'size' => filesize( $wp_styles->registered[ $handle ]->extra['path'] ), + 'src' => $src, + 'path' => $path, + 'size' => $size, ); } } diff --git a/wp-includes/version.php b/wp-includes/version.php index 5fd6aacf50..f4df3ef091 100644 --- a/wp-includes/version.php +++ b/wp-includes/version.php @@ -16,7 +16,7 @@ * * @global string $wp_version */ -$wp_version = '6.3-alpha-55887'; +$wp_version = '6.3-alpha-55888'; /** * Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.