[wp-trac] [WordPress Trac] #31950: Reduce PHP memory usage / No unnecessary concatenation

WordPress Trac noreply at wordpress.org
Sat Apr 11 17:58:13 UTC 2015


#31950: Reduce PHP memory usage / No unnecessary concatenation
-------------------------+-----------------------------
 Reporter:  jrf          |      Owner:
     Type:  enhancement  |     Status:  new
 Priority:  normal       |  Milestone:  Awaiting Review
Component:  General      |    Version:  trunk
 Severity:  normal       |   Keywords:
  Focuses:               |
-------------------------+-----------------------------
 While these code changes might just seem a trivial cosmetic / code style
 change to some, in reality they aren't.

 Concatenation has a large impact on memory usage in PHP. The `echo`
 language construct can echo several things without concatenation by using
 commas.
 Replacing all concatenations within echo statements in favour of commas
 reduces the memory used by PHP.
 I haven't bench marked the effect yet [if someone's got a setup designed
 for that - please feel invited!].

 But consider this: Even if the reduction is just ~0.5%, 0.5% less memory
 use for 70 million sites world-wide has an impact.

 Some notes:
 I won't guarantee that I've caught every occurrence. This patch was
 created using regex searches on the code base for certain patterns such as
 `^\s*echo .+?\.` and then manually reviewing and adjusting the found code
 snippets.

 Also:
 - For the lines I've touched, I've made sure code style complies to the
 standard.
 - In some cases several echo statements where used when one would be
 sufficient. Merged a number of those (another best practice).
 - Some unnecessary double function calls, i.e. `echo sprintf()`'s replaced
 by `printf()`.
 - For the lines I've touched, I've done a sanity check for single quotes
 vs double quotes, especially if the resulting HTML would have single
 quoted attributes and adjusted accordingly.

 Code review appreciated.

 Specific review request:
 The below files each contained an output string without localization
 function. Was there a reason for that ? I've wrapped them in a `__()` now.
 - `wp-includes/locale.php`
 - `wp-includes/wp-db.php`
 - `wp-admin/includes/class-wp-importer.php`


 For more information, see:
 https://github.com/dseguy/clearPHP/blob/master/rules/no-unnecessary-
 string-concatenation.md
 https://github.com/dseguy/clearPHP/blob/master/rules/no-repeated-print.md

--
Ticket URL: <https://core.trac.wordpress.org/ticket/31950>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform


More information about the wp-trac mailing list