2 Jul 2009 21:38
[RCD] php code design/performance
darklight <darklight.xdarklight <at> googlemail.com>
2009-07-02 19:38:43 GMT
2009-07-02 19:38:43 GMT
Hi,
walking through roundcube's code I've found some room for small improvements.
if you sum them all together you may get some nice performance improvement
(not very huge - but you can probably notice it)
what I'm talking of are mainly style questions... because there are functions
in php that do the same as another function, with the small difference that
function X is faster
for example print() is slower than echo()
also double-quotes (") are up to 25% slower than concatenating strings
with single quotes (') - which is a HUGE performance boost
I've found a site which lists some of those functions - check [1]
I quickly compared the list with roundcube's codebase
those are the main places where there is still room for improvement:
* use ' instead of " (where possible - for example 'this is a test' . "\n"
would still be faster than "this is a test\n" - but you cannot replace
'"\n" by '\n')
* multiple parameters for echo - but most people prefer concatenating
over this multiple argument feature (I have to admit: I also prefer
string concatenation)
* pre-increment instead of post-increment (should be quite easy to do this,
since you need post-increment only in very few cases)
* unset() should be used more often (bigger task)
* use require() instead of require_once() - this is probably a bigger task too
one small note about [1]: afaik switch/case is faster than if/else
that site says the opposite
(Continue reading)
Usually, you would think that Google knows what they are doing, but it
seems like that is not always the case.
<at> Martin
If you are concerned about the speed, feel free to get Xdebug and
enable the profiler. It'll provide you with Cachegrind files which you
can view in WinCacheGrind (windows), KCacheGrind (linux/kde) or
webCacheCrind (browser).
Those files help you figure out bottle-necks in PHP code and if you
can solve any of them or want feedback on your discoveries, always
feel free to ping the list. Of course we're not holding back on
optimization, but we'd like to avoid the unnecessary.
Till
_______________________________________________
List info:
RSS Feed