Opened 11 years ago
Closed 11 years ago
#21332 closed enhancement (fixed)
Improve speed of add_query_arg()
Reported by: |
|
Owned by: |
|
---|---|---|---|
Milestone: | 3.5 | Priority: | normal |
Severity: | normal | Version: | |
Component: | Performance | Keywords: | has-patch |
Focuses: | Cc: |
Description
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.
In [21298]: