Tuesday, July 04, 2006

python2.5. faster startup, better memory use, faster.

Recently I was testing that pygame still works with the python2.5 beta. When I was doing this, I had a chance to play around with python2.5 and all it's new goodness. Amongst the other good python2.5 features is that python is performing better.

Almost twice as fast a startup 'cold'.

This is because it uses half the number of syscalls as python2.4 does. 755 syscalls in 2.4 and 461 in 2.5. Still not quite as good as perl with 40ish syscalls, but a massive improvement none the less.

$ time python2.4 -c "print 'hello'"

real 0m0.923s
user 0m0.041s
sys 0m0.025s

$ time python2.5 -c "print 'hello'"

real 0m0.417s
user 0m0.043s
sys 0m0.021s

However compared to perl, python is still syscall heavy. Perl does around 50ish syscalls to start up.

Python2.5 also frees up more memory that it isn't using.

Python2.4 does not release all that much memory if you use up quite a lot. It holds onto it in it's memory pool as an optimisation. The idea is that it is quicker to reuse memory, than to rely on the operating systems memory management. Unfortunately, this can be *really* bad for long running processes, and on machines which need to share with other processes. ie webservers, games, gui apps.

Even though there could still be improvements, my tests with real world applications using 2.5 show a much better use of memory. It gives back most of what is used. However for best use of memory it is still a good idea to restart processes if you can.