Friday, September 14, 2012

facebook's HipHop for PHP is a lie

Ever since I heard about hiphop (from a beginner dutch programer's website -- ), I had my doubts about the approach, and my belief was that real Cpp would have been so much better than automatic PHP to Cpp translation+compile.


I of course knew that PHP was half a billion times slower than Cpp (actually just about 31 times), and even much slower than C (35 times says the benchmark), which is also the level of "highly optimized C++" code.

On facebook's HipHop php page, the presentation of HipHop is that it takes 50% cpu of the apache/php combo.


We of course already know that simply pre-compiling the PHP will yield such results (actually far better in the case of something as simple as facebook's web pages) - and the immediate conclusion is that their hiphop compiler is totally unable to bring PHP code to C-like speeds.

We also know that there are other simpler webservers (that can fit the facebook bill) than apache's httpd out there, most of which beat it in CPU and memory usage - the very fact that facebook did not write their own pure C web server tailored to their own needs is a mistery to me, considering the scale and infra costs.


According to the benchmarks currently available on the web, when PHP code is hiphop compatible (some major stuff is not, and the half-compatible stuff will compile but end up much slower), it can see anywhere from the same performance to between 2 and 10 times better performance, i.e. between 4 and 17 times slower than real Cpp.

The other major observation everyone made is that the better memory handling in the compiled version led to memory savings between 25 and 50%.

Not that bad for a facebook hack ;) Too bad it's mostly due to precompile and not to code quality.




If that's what they call "highly optimized C++", I'll make sure to stay away from anything they write in C++, including hiphop.

Otherwise, if you can't be bothered to find programmers that know C-fu, you'll find hiphop or APC can save you a lot on server bills.

http://shootout.alioth.debian.org/u32/benchmark.php?test=all&lang=php&lang2=gpp
http://shootout.alioth.debian.org/u32/benchmark.php?test=all&lang=php&lang2=gcc
https://github.com/facebook/hiphop-php/wiki
http://translate.google.com/translate?hl=en&prev=/search%3Fq%3Dalioth%2Bshootout%26hl%3Den%26lr%3D%26client%3Dfirefox-a%26rls%3Dcom.ubuntu:en-US:official%26tbs%3Dqdr:d%26prmd%3Divns&rurl=translate.google.com&sl=pl&twu=1&u=http://php.webtutor.pl/pl/2011/03/26/co-najbardziej-spowalnia-skrypty-php/
http://php.webtutor.pl/en/2011/04/02/hiphop-for-php-bechmark-english-version/
http://php.webtutor.pl/en/2011/05/17/drupal-hiphop-for-php-vs-apc-benchmark/
http://cassandra-php.blogspot.be/2011/05/lightspeed-php-performance-and-scaling.html


Note: I have since then improved the PHP submissions to the computer benchmarks game, and the difference between native PHP and C++ has shrunk considerably. There are however major performance issues related to PHP arrays, and one would expect Cpp to solve that problem entirely (the problems are on the order of 100x slower).

No comments:

Post a Comment