[wp-trac] [WordPress Trac] #59405: Reduce the use of the `_wp_array_get()` function to improve performance

WordPress Trac noreply at wordpress.org
Tue Sep 26 13:45:39 UTC 2023


#59405: Reduce the use of the `_wp_array_get()` function to improve performance
---------------------------------------+-----------------------------
 Reporter:  aristath                   |       Owner:  SergeyBiryukov
     Type:  enhancement                |      Status:  closed
 Priority:  normal                     |   Milestone:  6.4
Component:  General                    |     Version:
 Severity:  normal                     |  Resolution:  fixed
 Keywords:  has-patch gutenberg-merge  |     Focuses:  performance
---------------------------------------+-----------------------------
Changes (by SergeyBiryukov):

 * owner:  (none) => SergeyBiryukov
 * status:  new => closed
 * resolution:   => fixed


Comment:

 In [changeset:"56709" 56709]:
 {{{
 #!CommitTicketReference repository="" revision="56709"
 Editor: Reduce the use of the `_wp_array_get()` function to improve
 performance.

 `_wp_array_get()` is an expensive function, and it's called thousands of
 times on each page view on the front end. While the function performance
 was slightly improved in #58376, it is still called more times than it
 should be.

 This commit aims to further optimize its usage:
 * In many cases, `_wp_array_get()` can be replaced with a much simpler and
 faster `isset()` check.
 * The `isset()` function is capable of checking nested arrays, so `isset(
 $foo['a']['b']['c'] )` will return false even if `$foo['a']` is unset,
 without throwing any errors or warnings.
 * When `_wp_array_get()` cannot be directly replaced with `isset()`, it
 would be good practice to wrap it in an `isset()` function so that
 `_wp_array_get()` only runs when it needs to.

 Original PR from Gutenberg repository:
 * [https://github.com/WordPress/gutenberg/pull/51116 #51116 Performance
 improvement: Reduce the use of the _wp_array_get() function]

 Follow-up to [55851], [56382].

 Props aristath, jrf, spacedmonkey, mukesh27, swissspidy, hellofromTonya.
 Fixes #59405.
 }}}

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


More information about the wp-trac mailing list