Facebook Rewrites PHP Runtime With HipHop

Last night, we reported that Facebook was planning to release a JIT compiler for PHP, a huge step toward making the PHP runtime - and PHP-based sites and apps - faster by taking the interpreted lagnuage (a.k.a., more human-readable code) a few steps closer to the bare-metal ones and zeros machines actually read.

We've been updated this morning that the PHP runtime has in fact been rewritten, with an extra step: The PHP is translated to C++ (a more machine-readable language) which is then compiled with g++. This project, called HipHop, has been in development under great secrecy at Facebook for the past couple years and has just this morning been open sourced.

Facebook engineer Haiping Zhao writes, "With HipHop we've reduced the CPU usage on our Web servers on average by about fifty percent, depending on the page. Less CPU means fewer servers, which means less overhead."

We're sure this is good news for Facebook's brand new data center, still under construction.

"HipHop executes the source code in a semantically equivalent manner," Zhao continues, "and sacrifices some rarely used features - such as eval() - in exchange for improved performance."

He also notes that while interpreted languages such as PHP, Ruby and Python - the languages that, by and large, rule the web of apps and social site we all use today - allow for huge strides in developer productivity, they are also less efficient and often simply slower in runtime. For a huge and ever-growing site such as Facebook, this might have eventually led to scalability issues.

In other words, it cost Facebook less to create a faster PHP runtime than to buy all the servers that would be needed to support hundreds of millions of users without a faster runtime.

"Scaling Facebook is particularly challenging because almost every page view is a logged-in user with a customized experience," writes Zhao. "When you view your home page we need to look up all of your friends, query their most relevant updates (from a custom service we've built called Multifeed), filter the results based on your privacy settings, then fill out the stories with comments, photos, likes, and all the rich data that people love about Facebook. All of this in just under a second.

"HipHop allows us to correct the logic that does the final page assembly in PHP and iterate it quickly while relying on custom back-end services in C++, Erlang, Java or Python to service the News Feed, search, Chat and other core parts of the site."

Zhao notes that PHP and C++ share relatively similar syntax, although C++ is by far less taxing on system resources. While it would have been impossible to write the codebase by hand, Zhao had been tinkering with programmatically converting PHP to C++ for a few years. He got the idea at a Facebook Hackathon, he said.

UPDATE: Late last night, we pinged PHP creator Rasmus Lerdorf on Twitter, asking for his opinions on the rumored PHP compiler. This morning, he wrote, "I think HipHop is cool and will certainly help the poor people stuck in framework soup." However, he also noted, "HipHop on simpler template-style PHP pages probably isn't going to help you too much. It's not going to make your SQL queries any faster."

We will update this post as news continues to break.

Category:  
You can follow any responses to this entry through the RSS 2.0 feed. You can leave a response.
0 Responses