[wp-trac] [WordPress Trac] #48082: Replace `dirname(__FILE__)` with `__DIR__` (Performance improvement, massive patch)
WordPress Trac
noreply at wordpress.org
Wed May 4 18:39:13 UTC 2022
#48082: Replace `dirname(__FILE__)` with `__DIR__` (Performance improvement,
massive patch)
------------------------------+--------------------------------------------
Reporter: ayeshrajans | Owner: SergeyBiryukov
Type: enhancement | Status: closed
Priority: normal | Milestone: 5.4
Component: General | Version:
Severity: minor | Resolution: fixed
Keywords: has-patch needs- | Focuses: performance, coding-standards
testing |
------------------------------+--------------------------------------------
Comment (by azaozz):
Replying to [comment:13 SergeyBiryukov]:
Coming back to this after some time, mostly for posterity. Think the
replacement of `dirname( __FILE__ )` calls with `__DIR__` (the original
purpose of this ticket) was great.
However the removal of parentheses around concatenated strings (that was
"attached" here later on) was perhaps a bad idea. It seems to make the
code a little bit harder to read in some places, mostly when several
strings are concatenated.
Did a quick test to see how much faster `include 'file.php';` is compared
to `include( 'file.php' );` as that was the reason to reduce code
readability. Running this 10k times in a loop did not produce any
measurable difference, seems the speed up is mostly theoretical.
The other change that was "attached" later seems to have a bit of negative
effect. Replacing `include` with `require once` seems to slow down PHP by
about 0.5% on my test server. Frankly I'm not sure why this was done
without any tests and why on this ticket.
--
Ticket URL: <https://core.trac.wordpress.org/ticket/48082#comment:19>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform
More information about the wp-trac
mailing list