From d0a54567b113446cc64651ce8fd5bc816c60b119 Mon Sep 17 00:00:00 2001 From: Dennis Snell Date: Fri, 5 Jun 2026 08:02:57 +0200 Subject: [PATCH] Performance: avoid over-allocation in wp_is_numeric_array() When a trace of allocations revealed that `wp_is_numeric_array()` accounted for a significant fraction of the allocations in a page render, it was observed that the function eagerly allocates and copies array keys and then filters them when all it wants to know is whether a single key in the array meets a condition. In this patch the `array_filter( array_keys() )` invocation is replaced with early-aborting iteration to avoid the memory allocation and copying. This patch prepared during WCEU 2026 Contributor Day. Follow-up to [34927]. Follow-up to 374b39d6ba1dfbffde425e37ca93c59d5b8d5190. --- src/wp-includes/functions.php | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/src/wp-includes/functions.php b/src/wp-includes/functions.php index 93b4df2df4505..6eb0d3911412f 100644 --- a/src/wp-includes/functions.php +++ b/src/wp-includes/functions.php @@ -5295,10 +5295,13 @@ function wp_is_numeric_array( $data ) { return false; } - $keys = array_keys( $data ); - $string_keys = array_filter( $keys, 'is_string' ); + foreach ( $data as $key => $_ ) { + if ( is_string( $key ) ) { + return false; + } + } - return count( $string_keys ) === 0; + return true; } /**