Smarty Forum Index Smarty
The discussions here are for Smarty, a template engine for the PHP programming language.

micro optimization

 
Post new topic   Reply to topic    Smarty Forum Index -> Smarty Development
View previous topic :: View next topic  
Author Message
kowach
Smarty Rookie


Joined: 26 Jan 2011
Posts: 13

PostPosted: Mon Oct 20, 2014 7:59 pm    Post subject: micro optimization Reply with quote

While I was analyzing bunch of xdebug trace code I found that is_array($parent) in Smarty->createTemplate is very costly, in Smarty-3.1.21/libs/Smarty.class.php(1305)

I guess that is because $parent is large Smarty object and checking it is heavy.

When I changed comparation to $parent===(array)$parent, function is_array had goone from xdebug top functions.

As said on stackoverflow: Micro-optimisation is worth it when you have evidence that you're optimising a bottleneck.
http://stackoverflow.com/questions/3470990/is-micro-optimization-worth-the-time

Sou please include it in next release Smile
Back to top
View user's profile Send private message
U.Tews
Administrator


Joined: 22 Nov 2006
Posts: 5059
Location: Hamburg / Germany

PostPosted: Tue Oct 21, 2014 12:19 am    Post subject: Reply with quote

I don't know how you could have seen is_array() in xdebug top functions. It's not costly.

1. It's execution time does not depend on the type of the variable, so the size of the smarty object does not matter.

2. The execution time on my system is just 6 usec , so it's one of the fastest function called.

3. If you replace it by $smarty === (array)$smarty ofcause you don't see it any longer in xdebug because it's not called anymore. But that does not mean that the $smarty === (array)$smarty needs not time. Tests on my system show that it does need about 4 usec. Okay it saves 1/3 of the exeution time of is_array().
But compared to the loading time of a page you may save a maximum of 0.01 % of execution time.

So I think you have missinterpreted some xdebug data.
Back to top
View user's profile Send private message
kowach
Smarty Rookie


Joined: 26 Jan 2011
Posts: 13

PostPosted: Tue Oct 21, 2014 7:37 am    Post subject: Reply with quote

I used this script to get top functions by time:
https://raw.githubusercontent.com/derickr/xdebug/master/contrib/tracefile-analyser.php

I'v done multiple tests, again. While trace shows improvement of $smarty === (array)$smarty for few milliseconds, apache bench shows degradation. I guess that xdebug trace data is not relevant because it dumps lot of data which can alter the timings.

So I was wrong Sad
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    Smarty Forum Index -> Smarty Development All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group
Protected by Anti-Spam ACP