More PHP Awesome from Facebook: The HipHop Virtual Machine is brought to you in partnership with:

John Esposito edits Refcardz at DZone, while writing a dissertation on ancient Greek philosophy and raising two cats. In a previous life he was a database developer and network administrator. John is a DZone Zone Leader and has posted 293 posts at DZone. You can read more from them at their website. View Full User Profile

More PHP Awesome from Facebook: The HipHop Virtual Machine

12.09.2011
| 3741 views |
  • submit to reddit

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.

 

Comments

Lucie Hauri replied on Thu, 2012/03/29 - 4:18pm

I know what you mean. We will have the same issue with the new timeline profile covers for facebook

Yaron Levy replied on Mon, 2012/06/11 - 12:31pm

This really looks interesting. Performance notwithstanding, the opportunities for much better static analysis are obvious here. There also seem to be more subtle benefits, such as singletons actually making sense (presumably one object could serve concurrent requests, fine tuned as needed by callers with dependency injection?) Thanks for releasing this.

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.