[wp-trac] [WordPress Trac] #17019: context arg for WP_Query filter application
WordPress Trac
wp-trac at lists.automattic.com
Fri Apr 8 16:50:46 UTC 2011
#17019: context arg for WP_Query filter application
-------------------------+------------------------------
Reporter: kevinB | Owner:
Type: enhancement | Status: new
Priority: normal | Milestone: Awaiting Review
Component: Query | Version:
Severity: normal | Resolution:
Keywords: has-patch |
-------------------------+------------------------------
Comment (by kevinB):
Replying to [comment:20 scribu]:
> You're merely replacing the overhead caused by extra function calls with
overhead caused by extra if checks.
>
> Given that add_filter() and apply_filters() are called so many times
throughout a request, I'd be very surprized if this "strategic
application" would yield any speed improvements.
>
Yes, the is_array() check in add_filter was a mistake so I've removed that
in the revised patch. apply_filters() is not affected, as the context
check is in apply_filters_ref_array() - used mainly by WP_Query to the
tune of 26 per typical query by my count.
Assuming a new optional arg to add_filter would not be appreciated either,
I'm instead proposing a new function:
{{{
function add_context_filter($tag, $context, $function_to_add, $priority =
10, $accepted_args = 1)
}}}
Functionally equivalent alternatives welcome.
> Anyway, first rule of optimization: show me the tests.
>
Test script and results are attached. Now you might argue that the
improvement for likely use cases is insignificant, but I don't see how you
can reject this for performance concerns.
--
Ticket URL: <http://core.trac.wordpress.org/ticket/17019#comment:22>
WordPress Trac <http://core.trac.wordpress.org/>
WordPress blogging software
More information about the wp-trac
mailing list