Friday, 29 August 2008

PHP Opcodes

For most of the last three months I have been keeping myself busy working on a project that's related to PHP and has involved looking at PHP performance.

It's been interesting and led me to try to understand a lot more about how the Zend engine works. I spent a lot of time reading some sections of the code, and using my favourite technique (yes, I'm sorry - it's printf()) to understand how things work.

After one particularly frustrating day I asked a colleague (Andy Wharmby) about the issue I was looking at. Then a miracle happened - he'd not only looked at it but had documented it (and many other things) in a set of charts.

When I read the charts a lot of things I didn't understand got clearer - so, with Andy's permission - I'm making his work available to the PHP world in case other people find them as useful as I did. You can download them in Open Office format here.

Andy asked me to make it clear that he wrote the charts almost two years ago, so there may be bits that are out of date, or even just plain wrong. If you see things that need to be fixed please send me a mail ( and I'll be happy to update the slides. Andy made extensive use of Sara Golemon's blog posts and tools written by Sara and Derick Rethans. Apart from that, like me, he used printf() and a debugger to look at the source for the engine.

I know that Gwynne is working on internals documentation for PHP, I am really looking forward to that. These charts, although very useful, are no substitute for a well written manual section!

Monday, 4 August 2008

PHP test coverage

I thought it might be interesting to compare the PHP test coverage from before the 2008 testfest with today's test coverage.

Here are two sets of gcov results - one based on a CVS extract of PHP 5.3 from May 1st 2008 and the second based on a CVS extract of PHP 5.3 from August the 1st 2008.

I had to copy a few files into odd places to make lcov run, however since I copied the same files in both source trees I think the results are comparable, even if they look a bit odd in places.

We know that 158 new tests came in from people submitting tests to the testfest site, three of the areas that these were targeted for improvement were ext/dom, ext/reflection and ext/exif. Here is how the coverage changed in these extensions:

/ext/reflection went from 73.6 up to 84.6

/ext/dom went from 56.7 to 60.3

/ext/exif went from 44.2 to 57.1

An average of nearly 10% over the three of them.

I'm looking forward to helping to run 2009 testfest. If we build on the successes of the 2008 we could aim to get several more extensions up to the same coverage as reflection.