[wp-trac] [WordPress Trac] #60510: Plugins Dependencies: performance improvements with finding plugin's file relative to plugins directory.
WordPress Trac
noreply at wordpress.org
Mon Feb 12 16:10:51 UTC 2024
#60510: Plugins Dependencies: performance improvements with finding plugin's file
relative to plugins directory.
-----------------------------+--------------------------
Reporter: hellofromTonya | Owner: (none)
Type: defect (bug) | Status: new
Priority: normal | Milestone: 6.5
Component: Upgrade/Install | Version: trunk
Severity: normal | Resolution:
Keywords: | Focuses: performance
-----------------------------+--------------------------
Description changed by hellofromTonya:
Old description:
> Micro-optimizations exist for finding each plugin's file relative to the
> plugins' directory within the following logic of the plugins' loader loop
> in `wp-settings.php`:
>
> {{{#!php
> foreach ( wp_get_active_and_valid_plugins() as $plugin ) {
> $plugin_file = str_replace( trailingslashit( WP_PLUGIN_DIR ), '',
> $plugin );
> }}}
>
> * The path to the plugin directory is a constant. Invoking the
> `trailingslashit()` within the loop for each plugin is unnecessary and
> less performant.
> Propose to move it before the `foreach()` loop.
>
> * `str_replace()` is less performant than `substr()` (see
> https://3v4l.org/TbQ9U).
> Propose: calcuating the plugins' directory path's `strlen()` before the
> loop and switching to `substr()`.
>
> Follow-up to [57545] / #22316 and [57592] / #60461.
New description:
Micro-optimizations exist for finding each plugin's file relative to the
plugins' directory within the following logic of the plugins' loader loop
in `wp-settings.php`:
{{{#!php
foreach ( wp_get_active_and_valid_plugins() as $plugin ) {
$plugin_file = str_replace( trailingslashit( WP_PLUGIN_DIR ), '',
$plugin );
}}}
* The path to the plugin directory is a constant. Invoking the
`trailingslashit()` within the loop for each plugin is unnecessary and
less performant.
Propose to move it before the `foreach()` loop.
* `str_replace()` is less performant than `substr()` (see
https://3v4l.org/TbQ9U).
Propose: calculating the plugins' directory path's `strlen()` before the
loop and switching to `substr()`.
Follow-up to [57545] / #22316 and [57592] / #60461.
References:
* `str_replace()` https://www.php.net/manual/en/function.str-replace.php
* `substr()` https://www.php.net/manual/en/function.substr.php
* `strlen()` https://www.php.net/manual/en/function.strlen.php
* Show the comparison in action https://3v4l.org/TbQ9U.
--
--
Ticket URL: <https://core.trac.wordpress.org/ticket/60510#comment:1>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform
More information about the wp-trac
mailing list