Seva's notes

Wisdom, Awareness, Responsibility :)

Is Facebook PHP HipHop bullshit?

with 17 comments

Update: with the release of HHVM 2.0 the below becomes entirely obsolete. Cheers!

Yes, it finally happened – Facebook announced the PHP to C++ translator. Hurray!
So, after reading the post I can assume it:

  1. parses PHP code,
  2. extracts PHP AST,
  3. converts to C++ AST and
  4. generates C++ code.

Honestly, it’s not the best way of optimization, but probably is a quick win (BTW, why did it take for them so long?), which theoretically might indeed generate efficient C++ code.

But wait, what do they report? “We’ve reduced the CPU usage on our Web servers on average by about1 fifty percent3, depending on the page2.”

I have some doubts:

  1. Where is the objective and comparative statistics?
  2. Did they even collect the general statistics, or just tested some pages to see the difference?
  3. 50%? That’s it? And how about the fact that C++ is actually 3-500 times faster (also here) (That would be 70% to 99% reduce of CPU). In fact the well known PHP Accelerators provide the same level of performance improvement as HipHop! It’s interesting, did they try any of them before entering the so called “Hackathon”.

In addition to reflections above, looking at the profiles of 2.5 coders which hacked the translator, I sorrowfully tend to estimate that the answer for the question in this Post’s subject is positive. Nevertheless I’m full of sincere hope that further info will dispel my suspects and prove that HipHop is actually a brilliant peace of software.

Written by Seva

2010-02-03 (February 3) at 02:05:49

Posted in development, integration, php, software, thought, web

Tagged with

17 Responses

Subscribe to comments with RSS.

  1. Haiping Zhao’s post on the Facebook dev blog was quite careful to acknowledge the other efforts that are out there to make PHP faster. He mentioned several PHP-to-C compiler efforts, APC, Zend’s bytecode cache and Quercus.

    Since it’s clear that Zhao is well aware of the alternatives, I am prepared to wait another hour and a half and see what hiphop can actually do before leaping to the conclusion that it is no faster than the above.

    As for this comment:

    “50%? That’s it? And how about the fact that C++ is actually 3-500 times faster…”

    You’re referring to the speed of competently hand-written PHP for the same job, as interpreted by a very smart human being.

    That is not the same thing as asking a computer program to take a piece of PHP code and convert it to equivalent C++ code without doing anything that might, given one set of inputs or another, alter its behavior.

    The human knows that those inputs are always going to be integers, but the PHP compiler can’t possibly, because PHP is a weakly typed language (for the most part).

    So it converts the PHP bytecodes to equivalent C++, applies whatever type inference it *can* get away with to make it slightly faster C++, and hopes for the best.

    That’s very difficult work, but if anyone is motivated to make it happen, it’s Facebook – the biggest PHP server farm there is. Facebook saves real $$$ every time they shave a percentage point off the runtime of a PHP script.

    All that said, I’ve found that the really big performance gain with PHP is simply enabling APC. Bytecode caching should have been standard equipment from the beginning. With modern frameworks with thousands of PHP class files, it’s indispensable.

    Tom Boutell

    2010-02-03 (February 3) at 04:09:10

  2. “50%? That’s it?”
    Are you trolling to get more comments or you just have no idea what you’re talking about ?

    Most websites use opcode PHP opcode caching of some sorts (eAccelerator, APC and so on). It just pure bullshit trying to claim that one of the biggest PHP website out there hires developers who can manage to code PHP to C++ converter but cannot manage to install a decent opcode cache… Bold claim for a single guy 😛

    And today’s websites are not just some pure PHP stuff, serving only templates etc. Lots of performance issues are at the database. First the connection to database takes time to establish (also connection to memcached server). Then querying the results back takes some time. Since databases and memcached server are held separate from webservers, the data packets lag a bit and the whole time they are coming in, PHP website is waiting for them. Thus not a 100 times faster result, because hiphop improves PHP code execution, but does nothing to the database side.

    And also as Tom Boutell mentioned, you cannot convert typeless PHP code automatically to the c++ best equivalent, because when it’s not possible to use int type for sure, it will have to fall back to other mechanism that is more CPU expensive (using strings comes to mind). With some more code hinting using intval or int casting in PHP, the c++ code could be made more optimal with those hints. So for better performance, PHP code would need to be tuned to help the compiler.

    Anyhow, I’d like to see measured time generation times and time usage explanations before jumping to any accusations 😛 50% less CPU usage means they can double their userbase with same hardware: that’s some pretty impressive stuff considering their current userbase.


    2010-02-03 (February 3) at 10:16:38

  3. Well, I’ve just seen the presentation Unfortunately, my opinion hasn’t changed yet.


    2010-02-03 (February 3) at 11:13:09

  4. You forgot to mention that they also claim to make PHP thread safe, which means a thread for a faster DB connections.

    If HipHop does in fact thread everything, (and provide it’s very own web server as well) than this is a massive achievement.

    Also, thank Facebook for open sourcing all the code. In time we will see if HipHop transforms PHP (zend) as we know it.

    Ioncube replacement?
    Opcache replacement?

    Very interesting if nothing else, and it seems to be working for Facebook. For smaller PHP projects, HipHop is probably over kill.

    hell, if it can translate PHP to C++, what is anyone to stop it from porting to translating Ruby, Python or any other language.

    After being open sources, I am sure it wil be more optimized. That is why facebook open sourced it.

    Matt Kukowski

    2010-02-03 (February 3) at 12:24:10

  5. Hopefully someone can thoroughly benchmark it soon and publish exact numbers and what exactly becomes faster, by how much etc. I would personally like to see how much faster are the page generation times for non-db applications, for db applications etc. If they support autoloading of files and so on.
    50% lower CPU usage for already heavily optimized codebase is a big win in itself, but little vague though.
    I need MORE INFO 😀


    2010-02-03 (February 3) at 03:23:17

  6. where is hiphop to download? They’ve been talking about it but no one has pointed to any link where this actual program can be found…


    2010-02-05 (February 5) at 06:17:19

  7. Thanks for writiing this article, however, I guess it’s pretty pointless to judge anything without running actual benchmarks for the sake of comparison. It would be nice to see how HipHip PHP compares to the most popular PHP accelerators. At this point it’s hard to say whether or not some of the claims are realistic or rather ambitious.


    2010-03-27 (March 27) at 11:22:28

    • My point is the following: If the developers didn’t care to perform even the minimal benchmarking before announcing their work, it probably means they are not competent enough in software engineering, thus their product is probably is BS. Again, this is only an estimation based on my personal experience. And I wasn’t sarcastic claiming that I will be happy to be wrong in this case.


      2010-03-27 (March 27) at 07:57:53

  8. It’s not bullshit. HipHop is not the first compiler for PHP and it’s not necessarily the best either (depending on your objectives). Apparenty compiling PHP to produce faster code is not so tough as you might think… there are at least half a dozen similar solutions (see the list at


    2010-04-29 (April 29) at 06:30:13

  9. If I’m not mistaken, HipHop does NOT take into account the dynamic nature of PHP, because C++ is static and strongly typed. So, HipHop probably works best only for FaceBook applications (that probably don’t use dynamic variables), and not just ANY PHP code out there.


    2010-08-15 (August 15) at 03:08:45

  10. To add to my above comment, since HipHop doesn’t take into account the dynamic nature of PHP, what does it accomplish ?

    Hence, HipHop to me simply seems an altogether new compiled programming language, whose syntax is the same as PHP. Lets call it PHC++.


    2010-08-15 (August 15) at 03:11:55

  11. Abhid-D, it’s available and others have posted statistics and described what works and what doesn’t. There’s no reason to speculate without information.

    Yes, HipHop takes into account the dynamic nature of PHP. That’s why the performance boost is “only” 50%.

    Still, for 99% of sites, and all sites that haven’t already enabled APC at a bare minimum, HipHop is totally overkill.

    Tom Boutell

    2010-08-15 (August 15) at 03:45:15

  12. Tom Boutell, I read FaceBook’s team’s lecture in which they said that dynamic features are first removed, or at least minimized before they are run through HipHop.

    Facebook is now consulting WordPress and other PHP heavy-users on applying HipHop. It was said that they consult them on minimizing the dynamic portions of their code.

    The only language that faithfully converts PHP code is Scala (I don’t endorse it. Just saying matter-of-factly). That’s because it has features of both, weakly typed as well as strongly typed languages.



    2010-08-16 (August 16) at 07:06:24

  13. Abhid, you are misunderstanding what they said. They remove dynamic features because they are hard to optimize to make them any faster, not because they can’t be run by HipHop at all. There may be features HipHop can’t handle but this has nothing to do with being implemented in C++.

    The first Scala compiler was written in Java. Compilers for many loosely typed languages are written in C. Any Turing-complete language can be used to implement any other language, as you hopefully learned in your first computer science class.

    Tom Boutell

    2010-08-16 (August 16) at 07:17:28

  14. Well, the following release by HipHop’s creator specifies that only dynamic variables can be taken care of by the HipHop parser. Not allowed at all are dynamic scripting, eval(), create_function() amongst some others.

    Scala uses objects to represent nearly all data-types and return types, that’s why its able to translate PHP. HipHop on the other hand, determines which dynamic variables can be declared as one type safely.

    Actually I’m done arguing on this issue, as this is pretty much all that I’ve to say.


    2010-08-17 (August 17) at 06:42:47

  15. I see what you mean, and I apologize for my overly combative tone earlier.

    Not supporting the dynamic stuff is a choice they made, not something that C++ imposed on them. They could compile dynamically to C++ on the fly (which would be silly and slow if the code never got reused, of course), or include a PHP interpreter as well as a compiler for hybrid execution (a better idea).

    They do support normal PHP scalars (“might be a string, might be a number, might be an array”). It’s possible to implement that on top of C++, or even use a C++ class with operator overriding to represent the scalars. It just doesn’t produce particularly pretty C++.

    Scala has no eval() either, by the way.

    Tom Boutell

    2010-08-17 (August 17) at 06:55:00

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: