Over a million developers have joined DZone.

More PHP Awesome from Facebook: The HipHop Virtual Machine

DZone's Guide to

More PHP Awesome from Facebook: The HipHop Virtual Machine

· Web Dev Zone
Free Resource

Learn how to build modern digital experience apps with Crafter CMS. Download this eBook now. Brought to you in partnership with Crafter Software

Nobody can fault Facebook for performance, and they have already done several wonders with PHP performance in the past.

Their HipHop PHP to C++ translator shrank the cycles from the upper end, squeezing out the pre-C++ fat. But even the C++ to x64 translation wasn't efficient enough -- for one thing, the dynamic->static match wasn't very good.

So Facebook approached PHP performance from the lower end: they created special HipHop bytecode (HHBC), built a virtual machine for HHBC, and a dynamic HHBC->x64 translator. 

Today Facebook posted a full explanation of the HipHop virtual machine, recalling the sweetness of those CS courses that kept you awake in school but faded into forgetfulness as you began to face tough development deadlines (or just switched over to mostly high-level languages)...

It does work faster (1.6 times). Here's the heart of the tech, in Facebook's words:

Throughout the hhvm project we have tended toward simple solutions. This is nowhere more evident than in the core premise of the dynamic translator itself. Most existing systems use method-at-a-time JIT compilation (e.g., Java and C#), though trace-based translation has also been explored in recent systems (e.g., Tamarin and TraceMonkey). We decided to try a very simple form of tracing that limits each trace to a single basic block with known input types. This "tracelet" approach simplifies the trace cache management problem, because complex application control flow cannot create a combinatorial explosion of traces.

This makes more sense with diagrams and examples, so check out the full blogpost, the bytecode spec, or the full HipHop project. And fall in love with PHP wizardry all over again.


Crafter is a modern CMS platform for building modern websites and content-rich digital experiences. Download this eBook now. Brought to you in partnership with Crafter Software.


Opinions expressed by DZone contributors are their own.

The best of DZone straight to your inbox.

Please provide a valid email address.

Thanks for subscribing!

Awesome! Check your inbox to verify your email so you can start receiving the latest in tech news and resources.

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}