Backend Development 7 min read

Facebook’s Evolution from PHP to HHVM: Improving Backend Performance

The article explains how Facebook transitioned from a PHP‑centric architecture to the HipHop Virtual Machine (HHVM) by first creating the HipHop compiler, addressing performance bottlenecks, and ultimately open‑sourcing a trace‑based bytecode VM to accelerate backend services.

Art of Distributed System Architecture Design
Art of Distributed System Architecture Design
Art of Distributed System Architecture Design
Facebook’s Evolution from PHP to HHVM: Improving Backend Performance

When examining most Facebook page URLs, many end with the .php suffix, reflecting the company’s heavy reliance on PHP for its web‑front development. PHP’s popularity and ease of use allowed rapid feature rollout, but the massive traffic (hundreds of billions of visits per month) exposed performance limitations, prompting Facebook to seek substantial improvements.

Initially, Facebook focused on tuning the Zend engine—patching compatibility issues and writing C++ extensions—to alleviate runtime load. However, senior engineer Haiping Zhao argued that this approach would fragment resources and demand deep C++ expertise, which conflicted with Facebook’s goal of keeping most engineers on PHP.

In 2010, Facebook shifted its effort to develop a new program interpreter called HPHP (or “HipHop”), which first parses PHP scripts into an abstract syntax tree (AST) and then translates the AST into optimized C++ code. Converting PHP to C++—a concept previously explored by projects like Roadsend—allowed seamless integration with Facebook’s existing C++ backend services. HipHop roughly doubled execution speed and halved server utilization, benefits that also extended to other PHP platforms such as WordPress.

Despite these gains, HipHop introduced challenges: it did not fully implement every PHP feature, documentation was sparse, and debugging with the standard PHP interpreter became ineffective. To address debugging, engineers created HPHPi, a PHP interpreter that mirrored the translation behavior, but HPHPi remained slower than native PHP and suffered compilation errors when analyzing the AST.

The limitations of converting dynamic PHP code to a statically compiled language—especially around variable handling, data types, and function semantics—highlighted the need for a different solution. This led to the creation of HHVM (HipHop Virtual Machine), which retains the AST approach but emits bytecode instead of C++ code. Unlike Java or C#’s just‑in‑time compilation, HHVM uses trace‑based translation, similar to Mozilla’s TraceMonkey, generating bytecode that a just‑in‑time interpreter then executes.

As of the article’s writing, HHVM was about 90% complete, with its interpreter reportedly 60% faster than HPHPi, though still only a quarter of the speed of fully compiled code. Facebook continued to address static‑language conversion issues, aiming to run all its products on HHVM. Both HHVM and the original HipHop compiler were open‑sourced on GitHub under PHP and Zend licenses.

phpVirtual Machinebackend performanceHHVMHipHop
Art of Distributed System Architecture Design
Written by

Art of Distributed System Architecture Design

Introductions to large-scale distributed system architectures; insights and knowledge sharing on large-scale internet system architecture; front-end web architecture overviews; practical tips and experiences with PHP, JavaScript, Erlang, C/C++ and other languages in large-scale internet system development.

0 followers
Reader feedback

How this landed with the community

login Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.