Opened 6 years ago
Last modified 3 years ago
#45854 new defect (bug)
Avoid printf/sprintf strings to be "double-quoted"
Reported by: | arena | Owned by: | |
---|---|---|---|
Milestone: | Awaiting Review | Priority: | normal |
Severity: | normal | Version: | |
Component: | General | Keywords: | has-patch close |
Focuses: | Cc: |
Description
No need to have double quoted strings in printf/sprintf.
Strings do not need to be evaluated by php.
Less cpu, less energy and a nicer planet !
patch sample hereattached.
Attachments (1)
Change History (6)
#1
follow-up:
↓ 3
@
6 years ago
Do you have a modern benchmark showing it is faster?
When there is no variable present in the string, PHP will use identical opcodes for the string if its a single vs double, so there's no difference in performance.
#3
in reply to:
↑ 1
@
6 years ago
Replying to chriscct7:
Do you have a modern benchmark showing it is faster?
When there is no variable present in the string, PHP will use identical opcodes for the string if its a single vs double, so there's no difference in performance.
"When there is no variable present in the string" means that PHP has to check if there is no !!!
#4
@
6 years ago
Yes but it does that while producing the opcodes, not when it runs those opcodes for execution. Most servers use an opcache layer, so you're not compiling the opcodes for each runtime, and therefore there's no difference. Even where ones where there's no opcaching enabled, in modern day (PHP 5.2+, particularly in PHP 7.x branches which WP is moving toward making it's minimum supported PHP version by EOL) PHP the speed of lexing for a variable is so fast that there is no measurable difference even if you run the test runs millions of times.
It's like removing a fly from an aircraft carrier to save weight & fuel consumption. In theory can it make a difference, yes. In any production environment will it ever make a difference, no.
A good resource that explains a lot of this can be found at https://nikic.github.io/2012/01/09/Disproving-the-Single-Quotes-Performance-Myth.html
sample to illustrate the ticket