More PHP Awesome from Facebook: The HipHop Virtual Machine
Join the DZone community and get the full member experience.
Join For FreeNobody 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.
Opinions expressed by DZone contributors are their own.
Comments