[wp-trac] [WordPress Trac] #26640: [Patch] Performance Increase in apply_filter() (~11%)
WordPress Trac
noreply at wordpress.org
Mon Dec 16 10:57:32 UTC 2013
#26640: [Patch] Performance Increase in apply_filter() (~11%)
-------------------------+-----------------------------
Reporter: dshafik | Owner:
Type: enhancement | Status: new
Priority: normal | Milestone: Awaiting Review
Component: General | Version: trunk
Severity: normal | Keywords:
-------------------------+-----------------------------
Currently apply_filter() simply calls `call_user_func_array()`. This is a
fairly expensive way to call dynamic functions, especially compared to
`$foo = 'funcName'; $foo()` — the issue is variable arguments.
It is quicker however to do a switch on the number of params and call the
equivalent `$foo()` with a fallback to the old behavior.
Additionally, the loop used is inefficient:
{{{
do {
foreach( (array) current($wp_filter[$tag]) as $the_ )
...
} while ( next($wp_filter[$tag]) !== false );
}}}
The `next()` call here returns the same value as `current()` in the
`foreach`; by simply assigning the return to a variable in the
conditional, we remove that extra unnecessary `current()` call entirely.
{{{
} while ( $current = next($wp_filter[$tag]) !== false );
}}}
We have to call `current()` before the `do` however to assign a value to
`$current` on the first iteration.
--
Ticket URL: <http://core.trac.wordpress.org/ticket/26640>
WordPress Trac <http://core.trac.wordpress.org/>
WordPress blogging software
More information about the wp-trac
mailing list