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.

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