A new project which converts PHP code into C++ for a performance boost of as much as 50 percent

Feb 3, 2010 13:36 GMT  ·  By
Facebook reveals HipHop, a new project which converts PHP code into C++ for a performance boost of as much as 50 percent
   Facebook reveals HipHop, a new project which converts PHP code into C++ for a performance boost of as much as 50 percent

As one of the biggest websites in the world and certainly one of the most complex, Facebook is looking at any trick in the book to squeeze some more performance out of its infrastructure. One of the most ambitious undertakings, one it kept quiet about until now, HipHop for PHP is a project designed to speed up the popular programming language. In short, HipHop 'translates' PHP code into "highly optimized" C++ code which is then compiled and run on the servers.

"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. This project has had a tremendous impact on Facebook. We feel the Web at large can benefit from HipHop, so we are releasing it as open source this evening in hope that it brings a new focus toward scaling large complex websites with PHP," Haiping Zhao, the Facebook software engineer responsible for the idea and much of the development, announced.

PHP is one of the most popular programming languages on the web at this point. Its unique set of advantages has made it the language of choice for most web developers. It's relatively easy to pick up, yet incredibly powerful borrowing some of the best features of older programming languages. Facebook preferred it as its popularity with web developers meant that it was able to expand its engineering team easily and update its product in short cycles while also delivering a compelling product.

Its flexibility though isn't matched by its performance, being a scripting language means that it's inherently slower than complied languages, like C++, or even interpreter ones like Java. C++ though is significantly harder to master, so adopting it for Facebook while also expanding the team to keep pace with growth was impossible.

This is how HipHop came into being. The project came to be a couple of years ago when Zhao started to build a tool to convert PHP code into C++ one. The C++ source code was then compiled with the g++, the standard GNU C++ compiler. A year and a half of development later and HipHop was production ready.

Despite announcing it now, Facebook started deploying HipHop about six months ago and says that 90 percent of the traffic using the translated C++ code rather than the original PHP. Facebook says this move has enabled them to enhance CPU performance by as much as 50 percent in some cases. Practically, what it means is that Facebook can run one of the biggest sites on the planet on the same number of servers as it did even a year ago when it had less than half the number of users it does today, a significant cost saving.

Facebook is now open-sourcing the project and all 300,000 lines of code are going live in a GitHub repository soon, though it doesn't seem to be available at this time. The social network believes that the project should be more than welcome by the community, though the ones benefiting the most from it are large-scale websites, the likes of Facebook. While Facebook hasn't traditionally been the biggest open-source supporter out there, things are changing and it has released several projects under an open license, like the recent Tornado framework.