Make WordPress Core

Opened 6 years ago

Last modified 3 years ago

#45854 new defect (bug)

Avoid printf/sprintf strings to be "double-quoted"

Reported by: arena's profile 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)

#45854_class-wp-list-table.php.patch (3.4 KB) - added by arena 6 years ago.
sample to illustrate the ticket

Download all attachments as: .zip

Change History (6)

@arena
6 years ago

sample to illustrate the ticket

#1 follow-up: @chriscct7
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.

Last edited 6 years ago by chriscct7 (previous) (diff)

#2 @chriscct7
6 years ago

  • Keywords close added

#3 in reply to: ↑ 1 @arena
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 @chriscct7
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

#5 @pento
6 years ago

  • Version trunk deleted
Note: See TracTickets for help on using tickets.