[wp-trac] [WordPress Trac] #15061: Allow either array or string to be passed to locate_template

WordPress Trac wp-trac at lists.automattic.com
Thu Oct 7 18:16:21 UTC 2010


#15061: Allow either array or string to be passed to locate_template
--------------------------+-------------------------------------------------
 Reporter:  chrisbliss18  |       Owner:                 
     Type:  enhancement   |      Status:  new            
 Priority:  normal        |   Milestone:  Awaiting Review
Component:  Template      |     Version:                 
 Severity:  normal        |    Keywords:  has-patch      
--------------------------+-------------------------------------------------

Comment(by chrisbliss18):

 Replying to [comment:2 filosofo]:
 > Replying to [ticket:15061 chrisbliss18]:
 > > Note that this is just a very small sampling. In total,
 locate_template is used 89 times in BuddyPress
 >
 > Doesn't this fact argue against adding any unnecessary logic that would
 slow performance?  What is the advantage of using strings alone?
 You're misunderstanding me. It is used 89 times in the entirety of
 BuddyPress' code, not 89 times in a single page load.

 I decided to benchmark the code. The performance different when boiling
 down to just the difference in the old function and my patch's version is
 as follows for 10,000,000 function calls that randomly select between a
 string or an array argument:

 {{{
 Original: 11.932206869125
 Patch:    14.583618879318
 }}}

 So the performance penalty is a 22.22% increase in execution time. This
 amounts to a performance penalty of 0.000000265 seconds for an individual
 call.

 Looking at a standard page load (with BuddyPress since I talked about it
 in the ticket details), locate_template is called a total of four times.

 What is the advantage of using strings alone? It's a much easier to
 remember argument syntax and is more in-line with other similar functions
 such as load_template, get_template_part (which takes a string and
 converts it into an array to call locate_template with), and
 is_page_template.

-- 
Ticket URL: <http://core.trac.wordpress.org/ticket/15061#comment:3>
WordPress Trac <http://core.trac.wordpress.org/>
WordPress blogging software


More information about the wp-trac mailing list