Saturday, August 30, 2014
Facebook's HHVM 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.

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.

HHVM is intended to achieve both parity with the Zend Engine features and best possible performances. Facebook claims a 3x to 10x speed boost and 1/2 memory footprint by switching from PHP+APC to HHVM. But that is of course really application dependent (10x being for the FB code base).

Perfomance Optimization with Hack

Hack is an evolution of the PHP language designed to be safer, to enable better performance and to improve developer efficiency. Following are some of the areas where it has improved PHP to give us more performance-wise:

Type Annotations

Hack supports type annotation, which tells the runtime engine explicitly that a value is of a specific type. Run-time enforcement of return types and parameter types help HHVM's JIT produce more efficient code by making it safe to trust type annotations for optimization purposes.

Collections

Collections can hold values of the same type. HHVM can generate native machine code that is optimized for storing and retrieving collection values of a specific type from the collection, thus resulting in better performance.

Hassan Ahmad

Hassan is a web designer, developer who has been in this field for 6 years. He has special expertise in Java, C++, HTML/CSS, PHP, JavaScript and WordPress.

0 comments