[RCD] php code design/performance

darklight darklight.xdarklight at googlemail.com
Thu Jul 2 21:38:43 CEST 2009


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

some of those things can be put into roundcube's codebase quite easily
maybe you can create some "Junior Jobs" section in your wiki, so bored
devs may write patches (which of course should be reviewed by an
experienced dev)

however, feel free to discuss this
oh, and I know: this whole mail is not mean for today's development...
but more something for the future


[1] http://progtuts.info/55/php-optimization-tips/
List info: http://lists.roundcube.net/dev/

More information about the Dev mailing list