In this week’s blog, I’d like to talk about the HipHop Virtual Machine (HHVM).
What’s HipHop Virtual Machine?
This is a PHP processing platform developed by Facebook. Facebook’s entire site runs on HHVM (desktop, API, and mobile), both in development and production.
HipHop Virtual Machine is an open-source virtual machine designed for executing programs written in Hack and PHP. HHVM uses a just-in-time (JIT) compilation approach to achieve superior performance while maintaining the development flexibility that PHP provides.
HHVM supports Hack, PHP 5 and the major features of PHP 7. We are aware of minor incompatibilities, so please open issues when you find them. HHVM also supports many extensions as well.
HHVM was created as the successor to the HipHop for PHP (HPHPc) PHP execution engine, which is a PHP-to-C++ transpiler also created by Facebook. Based on the gained experience and aiming to solve issues introduced by HPHPc, Facebook decided in early 2010 to create a JIT-based PHP virtual machine. Issues associated with HPHPc included its reaching of a plateau for further performance improvements, lack of full support for all features of the PHP language, and difficulties arising from specific time- and resource-consuming development and deployment processes required for PHP projects that used HPHPc. In Q1 2013, the production version of facebook.com website stopped using HPHPc and switched to HHVM.
Following the JIT compilation principle, HHVM first converts the executed PHP or Hack code into a high-level bytecode, HHBC, which is also known as an intermediate language. HHBC is a bytecode format created specifically for HHVM, in a form that is appropriate for consumption by both interpreters and just-in-time compilers. As the next steps in execution, HHVM dynamically (“just-in-time”) translates the HHBC bytecode into x86-64 machine code, performs its additional optimizations through dynamic analysis of the translated bytecode, and executes the x86-64 machine code. As a result, HHVM has certain similarities to the virtual machines used by other programming languages, including the Common Language Runtime (CLR, for the C#language) and Java virtual machine (JVM, for the Java language).
HipHop Virtual Machine brings many benefits in comparison with HPHPc, and one of them is almost complete support for the entire PHP language as defined by the official implementation of PHP version 5.4, including the HHVM’s support for create_function() and eval()constructs. Furthermore, HHVM uses the same execution engine when deployed in both production and development environments, while supporting integration between the execution engine and the HPHPd debugger in both environment types; as a result, maintaining HPHPi (HipHop interpreter) separately as a development utility is no longer needed as it was the case with HPHPc. HHVM also eliminates the lengthy builds required by HPHPc to run PHP programs, resulting in much simpler development and deployment processes than it was the case with HPHPc.
Together with HipHop Virtual Machine, Facebook also released Hack, a derivative of PHP that allows programmers to use both dynamic typing and static typing, which is a concept also known as gradual typing, and allows types to be specified for function arguments, function return values, and class properties; however, types of local variables cannot be specified. At the same time, Hack does not provide complete backward compatibility by not carrying on some of the PHP features, such as the goto statement and dynamic variable names.
In September 2017, it was announced that version 3.24 would be the last version of HHVM to officially support PHP and that HHVM will only support Hack going forward, citing differences and incompatibilities in PHP 7
HipHop Virtual Machine release a new version every 8 weeks. At Facebook, HHVM is pushed every 2 weeks, but having everyone in the world update every 2 weeks would lead to too much testing and churn. After asking around this seems to be a good compromise between churn and getting new features. In the future, we could switch to every 6 weeks or 10 weeks or any multiple of 2 that the community likes.
There are definitely issues that need to be addressed with HHVM. The HHVM GitHub issues describe bugs that exist with the current implementation.
The HHVM team is working really hard to enhance functionality and fix bugs that currently exist.
HipHop Virtual Machine supported on
- Mac OS X: HHVM has experimental support on Mac OS X.
- Windows: HHVM is currently being ported over to Windows.
- Linux: HHVM has official Linux support on flavors of Ubuntu and Debian.
HipHop Virtual Machine Features
- The Hack Language
- JIT Compilation
- Proxygen and FastCGI support
- hphpd debugger
- … and more
The JIT Compiler
Rather than directly interpret or compile PHP code directly to C++, HHVM compiles Hack and PHP into an intermediate bytecode. This bytecode is then translated into x64 machine code dynamically at runtime by a just-in-time (JIT) compiler. This compilation process allows for all sorts of optimizations that cannot be made in a statically compiled binary, thus enabling higher performance of your Hack and PHP programs.
The above is my introduction to the new technology I know. I’m quite surprised and interested in HHVM. Since Facebook uses this, its feature is also quite superior. Please share your thought on the comment below.