You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Script Loader: Guard against exponential recursion during calculation of loading strategy and fetchpriority.
This addresses a performance issue in the recursive `WP_Scripts::get_highest_fetchpriority_with_dependents()` and `WP_Scripts::filter_eligible_strategies()` methods for redundant processing of shared dependencies in complex dependency graphs. To fix this, a `$stored_results` param is introduced which is passed by reference; this variable contains a cache of the calculated results for all scripts handles, so that subsequent calls for the same handle can return the cached value instead of re-computing it.
Developed in WordPress/wordpress-develop#10459
Follow-up to [60704], [60931], [56033].
Props ciobanucatalin, b1ink0, westonruter, mukesh27.
See #61734, #12009.
Fixes #64194.
Built from https://develop.svn.wordpress.org/trunk@61176
git-svn-id: https://core.svn.wordpress.org/trunk@60512 1a063a9b-81f0-0310-95a4-ce76da25c4cd
Copy file name to clipboardExpand all lines: wp-includes/class-wp-scripts.php
+21-11Lines changed: 21 additions & 11 deletions
Original file line number
Diff line number
Diff line change
@@ -997,12 +997,17 @@ private function get_eligible_loading_strategy( $handle ) {
997
997
*
998
998
* @since 6.3.0
999
999
*
1000
-
* @param string $handle The script handle.
1001
-
* @param string[]|null $eligible_strategies Optional. The list of strategies to filter. Default null.
1002
-
* @param array<string, true> $checked Optional. An array of already checked script handles, used to avoid recursive loops.
1000
+
* @param string $handle The script handle.
1001
+
* @param string[]|null $eligible_strategies Optional. The list of strategies to filter. Default null.
1002
+
* @param array<string, true> $checked Optional. An array of already checked script handles, used to avoid recursive loops.
1003
+
* @param array<string, string[]> $stored_results Optional. An array of already computed eligible loading strategies by handle, used to increase performance in large dependency lists.
1003
1004
* @return string[] A list of eligible loading strategies that could be used.
* @param array<string, true> $checked Optional. An array of already checked script handles, used to avoid recursive loops.
1074
+
* @param string $handle Script module ID.
1075
+
* @param array<string, true> $checked Optional. An array of already checked script handles, used to avoid recursive loops.
1076
+
* @param array<string, string> $stored_results Optional. An array of already computed max priority by handle, used to increase performance in large dependency lists.
1071
1077
* @return string|null Highest fetch priority for the script and its dependents.
@@ -1111,7 +1121,7 @@ private function get_highest_fetchpriority_with_dependents( string $handle, arra
1111
1121
}
1112
1122
}
1113
1123
}
1114
-
1124
+
$stored_results[ $handle ] = $priorities[ $highest_priority_index ]; // @phpstan-ignore parameterByRef.type (We know the index is valid and that this will be a string.)
0 commit comments