HipHop for PHP isn't technically a compiler itself. Rather it is a source code transformer. HipHop programmatically transforms your PHP source code into highly optimized C++ and then uses g++ to compile it. HipHop executes the source code in a semantically equivalent manner and sacrifices some rarely used features -- such as eval() -- in exchange for improved performance. HipHop includes a code transformer, a reimplementation of PHP's runtime system, and a rewrite of many common PHP Extensions to take advantage of these performance optimizations.The transformation process includes three main steps: 1. Static analysis where the system collects information on who declares what and dependencies 2. Type inference where it chooses the most specific type between C++ scalars, String, Array, classes, Object, and Variant 3. Code generation which for the most part is a direct correspondence from PHP statements and expressions to C++ statements and expressions. Overall HipHop allowed Facebook to keep the best aspects of PHP while taking advantage of the performance benefits of C++. In total, they have written over 300,000 lines of code and more than 5,000 unit tests. All of this is released on GitHub under the open source PHP license.
News: Facebook Releases HipHop JIT
Facebook announced the HipHop for PHP runtime environment. HipHop provides JIT capabilities to PHP that supercede the traditional PHP runtime and provide better page rendering performance with lower CPU usage. HipHop helps to provide massive PHP scalability and optimal interfacing with Java, Python, and C++ back-ends. Rather than using a complicated HTML particle caching system, or source-level code transformations, Haiping Zhao of Facebook describes how HipHop works:
- Posted by: Eugene Ciurana
- Posted on: February 03 2010 09:47 EST
- Re: Facebook Releases HipHop JIT by Nagraj Chakravarty on February 03 2010 14:35 EST
- JIT what? by Jevgeni Kabanov on February 03 2010 16:59 EST
- Re: Facebook Releases HipHop JIT by Bruce Fancher on February 04 2010 23:18 EST
- Link is broken by e a on February 08 2010 08:27 EST
- No eval? by Joao Del Valle on February 10 2010 07:27 EST
Very nice work. But does it do all the operations (1. Static analysis, 2. Type inference 3. Code generation , 4. Compilation of C++ in binary ) at run time? Isn't a just-in-time compiler kick in at run time ?
Very nice work. But does it do all the operations (1. Static analysis, 2. Type inference 3. Code generation , 4. Compilation of C++ in binary ) at run time?Based on how PHP works, and how they extended it, this is effectively happening "at run-time". The operations are optimized upon page requests and the decision to run a PHP script through this process is automated. I think the most interesting part of this approach is that it entirely bypasses the "gold standard" of PHP performance engines, Zend. HipHop indicates that Facebook believes it's easier and more cost-effective to come up with this JIT setup than to try to tweak Zend into doing what they need. Cheers! E http://ciurana.eu
Isn't a just-in-time compiler kick in at run time ?
Awesome news! Wonder if Quercus is faster than HipHop? @Eugene Was the "JIT" part mentioned anywhere or did you just add it yourself? JIT stands for Just-In-Time, which is an adjective, not a noun, so it doesn't make any sense in this context. Also I don't see it mentioned anywhere else and it's not what is commonly understood as a just-in-time compiler as they are definitely doing the compilation ahead-of-time.
Another solution for faster PHP code is P8, part of ProjectZero: http://www.projectzero.org/wiki/Development/PhpWebWhatPHP http://www.projectzero.org/php/
I wonder how the performance compares with Quercus?
I wonder how the performance compares with Quercus?Indeed, I'm very curious about that too.
The github link provided above does not work ATM. This is the address of the discussion group: http://groups.google.com/group/hiphop-php-dev?pli=1
Good work! I'm wondering if without eval() we won't loose some nice dynamic aspects of PHP. I can think of a few frameworks that would not work on HipHopJIT. What about reflection and references like $this->$$varName ?