HipHop: Facebook runs compiled PHP on its servers

While PHP deservedly gets a terrible rep around programming language folks, this is still an interesting announcement: HipHop compiles PHP down to C++ and gets about a 2x speedup. HipHop will be released as open source, and is currently in production use, serving 90% of Facebook's traffic. It makes me wish Facebook used Python: a large-scale deployment like this would be a great boon to the PyPy project.

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.

yikes

C++ code-generated Perl - kind of feel queasy just thinking about it. Like a pit of slimy orcs working the mines for Sauron, in my mind's eye I'll now see the workings of every Facebook status update and the eating away of all that is true and good.

In all fairness, LtU is run

In all fairness, LtU is run by PHP. :)

Puzzling

I've just read the announcement I did a lot of head scratching while doing so. There are many statements with which I disagree (though probably it is overly pedantic to pick on things like "HipHop for PHP isn't technically a compiler") but the whole approach just seems odd. I'd expect a 2x speedup from just writing a simple JIT for Zend. That would have the additional benefits of supporting all of PHP and allowing for trace guided optimisations, which is where the real speedups are to be found (in a language so poorly suited to static analysis).

1.) They don't need to

1.) They don't need to support all of PHP, only the bits they use.
2.) A JIT for Zend would lead to massive code generation. Each opcode does a stunning amount of work.
3.) Trace guided optimizations aren't so useful if your request only runs for 400ms. It could run over many many requests, but that's starting to be quite challenging. Static compilation is probably their sweet-spot.

I thought the idea for

I thought the idea for hotspot etc. was to run over multiple requests. Similarly, isn't JS, the popular target for trace opts, a lot of short seemingly run-once code?

Re: Puzzling

I think that the thinking went along the lines of "We have run into economic and/or technical issues adding more servers as we grow. We need to squeeze more performance out of existing infrastructure without rewriting our business logic as it may introduce too many bugs". And they came out with optimizing PHP the only way they knew how: static-compile it!

I doubt they went and hired best language, runtime or compiler designers, they just got their brightest programmer to do something about it. My first choice would be to see if I can translate the code into LLVM.

http://llvm.org/devmtg/2008-08/ Naive PHP -> LLVM implementation = 21x slowdown. Good times.

Science is calling...

The results in the slides showed an average slow-down of about 2x. The 21x slowdown was for Hello World. Reporting this accurately makes a bit of a difference.

The language matrix needs updating

Who is going to update the language matrix?

It's good that C++ is good at being C++!

Are so many people *really* surprised by this? Startling. I write little compilers that target C++ with some frequency-- and, why not? For a ubiquitous language, C++ has a superb semantic model! (Now, more than ever: "http://www2.research.att.com/~bs/macis09.pdf")

Seriously, why would someone /not/ want to leverage the advantage? I think that the reason is more historic than new: people think that "dynamic languages" are something new, when they just aren't.

C++ is much cooler than most people think. :-D

-Jesse

OT: C++ superb semantic model?

The IPR can represent all of C++ with just slightly less than 200 node types;

200 node types? Scheme can have as few as 7 (depending on how you slice up the core language.) Smalltalk has roughly 20. I guess it matters on what your measurement of superb is.

more languages

language matrix, now with more languages!

Hip-hop source available

Source is available on github.

Related talk and video on how it works.

Lambda / create_function

I think it's interesting that until recently, PHP's only lambda facility (known to me; create_function) was just a crude wrapper around eval. I wonder whether hiphop has any sort of support for lambdas at all.