HipHop for PHP
||It has been suggested that some portions of this article be split into a new article titled HHVM. Please discuss this on the article's talk page. (April 2014)|
|Initial release||February 2, 2010|
|Stable release||3.0.1 / April 4, 2014|
|Written in||C++, C, PHP|
|License||Free software (PHP License)|
|As of||May 2013|
HipHop for PHP (shortened as HipHop) describes a series of PHP execution engines and improvements created by Facebook. The original motivation of HipHop was to save resources on Facebook servers, given the large PHP codebase of facebook.com. As development of HipHop progressed, it was realised that HipHop could substantially increase the speed of PHP applications in general. Increases in web page generation throughput by factors of up to 6 have been observed over Zend PHP. A stated goal of HipHop is to provide a high level of compatibility for Zend PHP, where most Zend-based PHP programs run unmodified on HipHop. HipHop was originally open-sourced in early 2010.
The current version of HipHop, known as HHVM (HipHop Virtual Machine) was open-sourced in late 2011.
History before HHVM
HipHop (known as HPHP) is an execution engine for PHP. Beginning in 2008, Facebook engineers began working on HPHP. The original release of HPHP was as a PHP to C++ compiler, known as HPHPc. PHP code was written and, when run through HPHPc, was transformed into C++, compiled into a binary and run as an executable (as opposed to being compiled to opcodes and interpreted). At the peak of HPHPc, PHP code showed dramatic performance improvements (up to 6×) compared to Zend PHP.
As an adjunct to HPHPc, Facebook engineers also created a "developer mode" of HipHop (known as HPHPi) and the HipHop debugger (known as HPHPd). This allowed developers to run PHP code through the same logic provided by HPHPc while, at the same time, allowing them to interactively debug PHP code. Developers could set watches, breakpoints, etc. Of course, the code run through HPHPi was not as performant as the code run through HPHPc, but the developer benefits were, at the time, worth having to maintain these two execution engines for production and development. HPHPc, HPHPi and HPHPd were all open-sourced in 2010.
By many accounts, HPHPc was a huge success, especially within Facebook as it allowed facebook.com to run much faster, using fewer resources. However, in early 2013, Facebook deprecated HPHPc. There were many reasons for this. For all the performance gains that HPHPc provided, the curve for further performance improvements had flattened. HPHPc did not fully support the PHP language, including the create_function() and eval() constructs. HPHPc required a very different push process, requiring a bigger than 1 GB binary to be compiled and distributed to many machines in short order. HPHPc did not support HPHPd, and, given the amount of lines of code that made up facebook.com, HPHPi was becoming slow for development. Plus, maintaining HPHPc and HPHPi in parallel (as they needed to be for production and development consistency) was becoming cumbersome. Finally, it was not a drop-in replacement for Zend as external customers would have to change their whole development and build process to use HPHPc.
HipHop Virtual Machine (HHVM)
To solve the issues brought about by HPHPc, Facebook decided to create a PHP virtual machine. Foreseeing the possible issues arising with HPHPc, development on the HipHop virtual machine (known as the HHVM) began in early 2010. HHVM builds on top of HPHPc, using the same runtime and extension function implementations. HHVM converts PHP code into a high-level bytecode (commonly known as an intermediate language). This bytecode is then translated into x64 machine code dynamically at runtime by a just-in-time (JIT) compiler. In these respects, HHVM has similarities to virtual machines for other languages including C#/CLR and Java/JVM.
Facebook also released Hack, a programming language for HHVM that can be seen as a new version of PHP; it allows programmers to use both dynamic typing and static typing. An open-source version of Hack is part of the HHVM runtime platform.
HHVM brings with it many benefits over HPHPc. There is near full support for the entire 5.4 PHP language (including the create_function() and eval() functions). There is one execution engine for both production and development (i.e., no need to maintain HPHPi any longer). There is both production and development integration with HPHPd. And the push process becomes much simpler; no more lengthy binary build time that existed with HPHPc.
However, the key question is around performance. As a virtual machine, HHVM has the ability to use live type information to produce more efficient native code, leading to higher webserver throughput and lower latency. In Q4 2012, the performance of facebook.com running on HHVM achieved parity with HPHPc, while in December 2013 it was even surpassed by around 15%. In Q1 2013, the production version of facebook.com started running on HHVM, replacing HPHPc.
- facebook (2014-04-04). "Releases - facebook/hhvm". Github.com. Retrieved 2014-05-24.
- "OOPSLA '12 Paper". Retrieved 2013-05-23.
- "QCon 2012 HipHop Compiler Presentation". Retrieved 2013-05-23.
- "FOSDEM 2013 Interview". Retrieved 2013-05-23.
- "HipHop for PHP: Benchmark". Retrieved 2013-05-23.
- "Drupal 7: HipHop for PHP vs APC – benchmark". Retrieved 2013-05-23.
- "HipHop For PHP - Move Fast". Retrieved 2013-05-23.
- "The HipHop Virtual Machine". Retrieved 2013-05-23.
- "Announcement on GitHub removing HPHPc support". Retrieved 2013-05-24.
- "Hack: a new programming language for HHVM". Retrieved 2014-03-20.
- "GitHub - facebook / hhvm". Retrieved 2014-03-20.
- "GitHub issue discussion about PHP 5.4". Retrieved 2013-05-24.
- "Zend compatibility tests hosted on GitHub". Retrieved 2013-05-24.
- "State of HHVM in late 2012". Retrieved 2013-05-24.
- "We are the 98.5% (and the 16%) « HipHop Virtual Machine". Hhvm.com. December 2013. Retrieved 2014-02-23.
- Official website
- HipHop Blog
- HPHP Facebook Group
- Internals of HHVM - talk given by HipHop engineer, Keith Adams, at QCon 2012
- HHVM Talk to Wikimedia in March 2013 - talk given by HipHop engineer, Andrew Paroski, at Wikimedia
- Scaling with HipHop - talk given by HipHop open source engineer, Sara Goleman, at PHP UK Conference 2013