Coderoncode

Random ramblings about code, programming and technology

Books


Social Media


Lead Developer @ Demac Media


© 2014. Allan MacGregor All rights reserved.

An Introduction to HHVM

HHVM (HipHop Virtual Machine) 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.

A little big of history

In early 2008 Facebook began working on HipHop(now HPHP), a PHP execution engine; its original motivation was to convert Facebook massive PHP code base into C++ in order to save resources and increase the application performance. The original release was known as HPHPc a PHP to C++ compiler.

For next 2 years Facebook continued working on HipHop adding HPHPi ( a 'developer mode' version of HPHP) and HipHop debugger known as HPHPd, this allowed developers to watch and step through the code and interactively debug PHP applications running on the HipHop platform.

At it's peak, HipHop PHP code showed up to 6x times better performance than its ZEND counterpart. However, there where several drawbacks to this first iteration of HipHop:

In light of these problems Facebook took two key actions on early 2010, the first was to open source the HipHop platform. -- Open sourcing a project like this is a great way to build a community around the project and getting external help from that community --/

At the same time Facebook started the development of the modern version of HipHop, known as HHVM (HipHop Virtual Machine), HHVM improves the strengths of HPHPc and corrects many of the critical problems.

HHVM was build on top of HPHPc and it works by converting PHP code into high level bytecode(an intermediate language) this bytecode is the translated into machine code dynamically at runtime by a JIT (Just-In-Time) compiler.

If you are like me you probably have a vague recollection of the concepts of bytecode, machine code and Just-In-Time compilers, so let's take a momentarily side step and quickly review these concepts and how the they play a key role on HHVM.

Bytecode, Machine code, JIT, Oh my ...!

The performance and speed gained by applying these techniques is what gives HipHop and subsequently HHVM its core strengths. Keeping a PHP code base while achieving performance comparable to compiled applications.

Currently HHVM supports PHP 5.4 almost on its entirety, however there are still numerous bugs that prevent some applications from running, for that reason Facebook has set as goal to have the top 20 open source PHP applications running on HHVM. The first popular application to achieve this was Wordpress.

What's next

So now that we have a better understanding of what HHVM does and the advantages if running it we can start testing our applications on HHVM. In a subsequent post I will be covering the setup of a dedicated Vhost for HHVM, running benchmarks against your applications and eventually (fingers crossed) how to run Magento on HHVM.

Word count: 719

Enjoyed the article? Follow me on Twitter or with RSS.

comments powered by Disqus