[wp-trac] [WordPress Trac] #58317: Refactor determine_locale() for performance

WordPress Trac noreply at wordpress.org
Fri Jun 23 15:47:01 UTC 2023


#58317: Refactor determine_locale() for performance
---------------------------------------------+--------------------------
 Reporter:  Cybr                             |       Owner:  swissspidy
     Type:  enhancement                      |      Status:  reopened
 Priority:  normal                           |   Milestone:  6.3
Component:  I18N                             |     Version:  trunk
 Severity:  normal                           |  Resolution:
 Keywords:  has-patch has-unit-tests commit  |     Focuses:  performance
---------------------------------------------+--------------------------
Changes (by Cybr):

 * keywords:  has-patch has-unit-tests reporter-feedback commit => has-patch
     has-unit-tests commit


Comment:

 The fallback no longer considers `get_user_locale()` when the `'wp_lang'`
 cookie or query is unusable; only `get_locale()`. I already spoke to
 @swissspidy about that, and since no harm could be done in practice, we
 concluded it's fine.

 In the real world, `is_admin()` is a little heavier than simply a `return
 true;`, so I upgraded the test to be more akin to the real world.

 Comparing to the latest PR (4608), my initially proposed patch is about
 1.06x faster on the front end: https://3v4l.org/BPjZk.
 And about 1.05x faster in the admin area: https://3v4l.org/kdEQF.

 I consider this difference negligible. Still, it proves that the short
 ternary operator can be used to speed up code.

 Using the same more thorough test on the previous PR (4510), my patch was
 [https://3v4l.org/UMJj3 1.01x] and [https://3v4l.org/UMJj3 1.17x] faster,
 respectively. I'm glad to see the changes in 4608 leveled out the impact
 it had on admin performance.

 I don't like that `! empty( $_GET['wp_lang'] )` is tested twice now, but
 fixing that without having short ternary available only makes things
 worse.

 All in all, the PR 4608 as-is Looks Good To Me!

-- 
Ticket URL: <https://core.trac.wordpress.org/ticket/58317#comment:25>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform


More information about the wp-trac mailing list