[wp-trac] [WordPress Trac] #48082: Replace `dirname(__FILE__)` with `__DIR__` (Performance improvement, massive patch)
WordPress Trac
noreply at wordpress.org
Thu Sep 19 23:54:40 UTC 2019
#48082: Replace `dirname(__FILE__)` with `__DIR__` (Performance improvement,
massive patch)
---------------------------+--------------------------------------------
Reporter: ayeshrajans | Owner: (none)
Type: enhancement | Status: new
Priority: normal | Milestone: Awaiting Review
Component: General | Version: trunk
Severity: minor | Resolution:
Keywords: needs-refresh | Focuses: performance, coding-standards
---------------------------+--------------------------------------------
Changes (by jrf):
* keywords: has-patch => needs-refresh
* version: => trunk
Comment:
Hi @ayeshrajans Thanks for taking the initiative for this!
I've reviewed the patch and have a couple of remarks:
1. In a lot of places the patch does not comply with the coding standards
regarding whitespace on the inside of parentheses. Please run `composer
format` over the patch to fix this.
2. As nearly all of these touch `include/require` statements, may this be
a good time to remove the unnecessary parentheses which are often used
with them ?
`include`/`require` are language constructs, not function calls and not
using the parentheses has an - albeit arginal - performance benefit.
{{{#!php
<?php
// Bad:
require_once( dirname( __FILE__ ) . '/admin.php' );
// Good:
require_once dirname( __FILE__ ) . '/admin.php';
}}}
The `WordPress-Extra` PHPCS ruleset actually contains a sniff which
already checks for this. If the unneeded parentheses would be removed, the
sniff could move from the `Extra` ruleset to the `Core` ruleset. /cc
@pento
3. I wonder whether it may be more descriptive to use `ABSPATH . WPINC`
instead of `__DIR__` (where applicable). Along the same lines, the test
`bootstrap.php` file defines a `DIR_TESTROOT` constant which can (and
probably should) be used in quite a lot of places.
4. I don't think files from external dependencies - such as GetID3,
PHPMailer, SimplePie or Text_Diff (etc) should be patched as it may make
the upgrade path in the future more difficult (checking if there are any
customizations should only yield ''real'' customizations.
Other than that, this looks good.
--
Ticket URL: <https://core.trac.wordpress.org/ticket/48082#comment:1>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform
More information about the wp-trac
mailing list