[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 15:41:02 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           |   Keywords:
  Focuses:  performance      |
-----------------------------+--------------------
 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.

-- 
Ticket URL: <https://core.trac.wordpress.org/ticket/60510>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform


More information about the wp-trac mailing list