[wp-trac] [WordPress Trac] #21332: Improve speed of add_query_arg()

WordPress Trac wp-trac at lists.automattic.com
Sat Jul 21 06:03:26 UTC 2012


#21332: Improve speed of add_query_arg()
-------------------------+-----------------
 Reporter:  nacin        |      Owner:
     Type:  enhancement  |     Status:  new
 Priority:  normal       |  Milestone:  3.5
Component:  Performance  |    Version:
 Severity:  normal       |   Keywords:
-------------------------+-----------------
 On my local install on edit.php, add_query_arg() is called 186 times, but
 it ends up being nearly 6% of total time, per some profiling by both me
 and kurtpayne. I've seen it called far more times on other pages. I've
 known it to be slow (not perceptually, simply from profiling outputs) and
 have avoided using it. Not fun for a utility function.

 What may normally be called micro-optimizations could have some impact at
 this scale. End result, the function is nearly twice as fast:
  * Remove error-suppression operators from func_get_args() and
 func_get_arg() — they're unnecessary, as these functions will never emit
 an error in this context. These were introduced in [1823] and proliferated
 since then. Fixing this alone is about one-third of the speed-up.
  * Avoid func_get_args() and func_get_arg() as much as possible, loading
 func_get_args() once as $args.
  * Smaller stuff: Remove unnecessary preg_match() and strlen() when trying
 to detect and chop off the protocol; don't cast a known array to an array.

 We could also switch from wp_parse_str() to parse_str(), effectively
 reverting the first piece in [5709/trunk/wp-includes/functions.php]. I see
 no reason to be calling the `wp_parse_str` filter here in a utility
 function, though it's been around for a while already and it's not like
 apply_filters() is slow.

-- 
Ticket URL: <http://core.trac.wordpress.org/ticket/21332>
WordPress Trac <http://core.trac.wordpress.org/>
WordPress blogging software


More information about the wp-trac mailing list