[wp-trac] [WordPress Trac] #14280: add_filter should accept an array of tags

WordPress Trac wp-trac at lists.automattic.com
Mon Jul 12 14:37:39 UTC 2010


#14280: add_filter should accept an array of tags
-------------------------+--------------------------------------------------
 Reporter:  sivel        |       Owner:     
     Type:  enhancement  |      Status:  new
 Priority:  normal       |   Milestone:  3.1
Component:  Plugins      |     Version:     
 Severity:  normal       |    Keywords:     
-------------------------+--------------------------------------------------
 Currently when you want to hook a single callback into multiple
 filters/actions you create an array and loop through it calling
 add_action/filter each time.  It would reduce code and make it easier to
 do this by just having add_filter accept an array of strings as it's first
 argument.  In addition tests have shown that it also improves overall
 performance of WP by using this.

 I talked to nacin on IRC recently about this and he was concerned about
 negative performance impacts that this may have, since most of our
 add_action/filter calls are for single tags.  I did some performance
 benchmarking and found the following results:

 With having add_filter accept an array it was 0.000002002716 seconds
 slower for single actions, but 0.000007534 seconds faster for a 4 action
 loop.  Without add_filter accepting an array each iteration of a foreach
 in the way we are currently handling it takes 0.00000885725 seconds,
 accepting an array each iteration takes 0.00000697374 seconds.  Which is a
 0.000001884 improvement during add_action/filter iterations.

 Overall on a default install of WP 3.1-alpha this modification actually
 improved performance by 0.00048398971558 seconds faster by having
 add_filter handle all of the looping.

 Anyway, this is an early patch and likely could use a bit of testing and
 independent benchmarking.

 At the moment I have not added this functionality to remove_action/filter
 and am not really sure we need it.

 Please provide feedback, test and provide your own benchmarks.

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


More information about the wp-trac mailing list