[wp-trac] [WordPress Trac] #58458: Move the load of `array_keys` to a different level in the `WP_Hook` class
WordPress Trac
noreply at wordpress.org
Wed Sep 13 19:45:28 UTC 2023
#58458: Move the load of `array_keys` to a different level in the `WP_Hook` class
-------------------------------------------------+-------------------------
Reporter: bor0 | Owner:
| spacedmonkey
Type: enhancement | Status: assigned
Priority: normal | Milestone: 6.4
Component: General | Version: 6.3
Severity: normal | Resolution:
Keywords: has-patch needs-testing has-unit- | Focuses:
tests dev-feedback | performance
-------------------------------------------------+-------------------------
Comment (by flixos90):
Sharing some benchmarks for the PR https://github.com/WordPress/wordpress-
develop/pull/5200:
* For a basic site with the initial content, the performance difference is
very small but seems consistent:
* `wp-total` metric with TT3 theme: 94.29ms instead of 95.12ms (0.9%
faster)
* `wp-total` metric with TT1 theme: 55.5ms instead of 55.97ms (0.8%
faster)
* While the difference is so small that it could be variance, using a more
synthetic edge case example confirms that this change brings a performance
benefit:
* Running a single filter hook with 100k basic callbacks takes 14.87ms
instead of 18.18ms (18.2% faster)
All benchmarks were using `npm run research -- benchmark-server-timing -u
http://localhost:8889 -n 100` (see https://github.com/GoogleChromeLabs
/wpp-research), and the Server-Timing implemented in the Performance Lab
plugin.
For the edge case benchmark, I added this code:
{{{#!php
add_action(
'init',
static function () {
for ( $i = 0; $i < 100000; $i++ ) {
$f = function( $value ) {
return $value;
};
add_filter( 'my_test_filter', $f );
}
perflab_server_timing_register_metric(
'my-test-filter',
array(
'measure_callback' => static function(
$metric ) {
$metric->measure_before();
apply_filters( 'my_test_filter',
'filtered-content' );
$metric->measure_after();
},
'access_cap' => 'exist',
)
);
}
);
}}}
Overall, while the real-world impact may differ, it is safe to say this is
a worthwhile performance improvement.
--
Ticket URL: <https://core.trac.wordpress.org/ticket/58458#comment:15>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform
More information about the wp-trac
mailing list