#60510 closed defect (bug) (fixed)
Plugins Dependencies: performance improvements with finding plugin's file relative to plugins directory.
| Reported by: |
|
Owned by: |
|
|---|---|---|---|
| Milestone: | 6.5 | Priority: | normal |
| Severity: | normal | Version: | 6.5 |
| Component: | Upgrade/Install | Keywords: | has-patch commit |
| Focuses: | performance | Cc: |
Description (last modified by )
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:
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 thansubstr()(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.phpsubstr()https://www.php.net/manual/en/function.substr.phpstrlen()https://www.php.net/manual/en/function.strlen.php- Show the comparison in action https://3v4l.org/TbQ9U.
Change History (7)
This ticket was mentioned in PR #6089 on WordPress/wordpress-develop by @hellofromTonya.
22 months ago
#2
- Keywords has-patch added
@hellofromTonya commented on PR #6089:
22 months ago
#3
Awesome @costdev. I'll commit it.
#4
@
22 months ago
- Keywords commit added
- Owner set to hellofromTonya
- Status changed from new to reviewing
Discussed and reviewed the changes with @costdev who approved the patch. Marking it for commit.
@hellofromTonya commented on PR #6089:
22 months ago
#6
Committed via https://core.trac.wordpress.org/changeset/57606.
For the Plugins Dependencies additions to the plugins' loader loop in
wp-settings.php, there are micro-optimization improvements for finding each plugin's file relative to the plugins' directory:Move the plugin directory logic to before the loop.
Calculate the plugins' directory path string length
strlen()before the loop and then switch to usingsubstr()instead ofstr_replace(). See the performance differences in action https://3v4l.org/TbQ9U).Trac ticket: https://core.trac.wordpress.org/ticket/60510