Facebook Hopes to Revolutionize PHP with "Hip Hop"


Little did we know that, for the last six months, Facebook has made use of a custom compiler for PHP that they refer to as "Hip Hop." Essentially, it takes your PHP source code, and converts it into C++, and is then compiled with G++. As a result, they've managed to reduce their CPU usage by 50%. This project has apparently been in development for the last two years, but has only today been released to the community.

"HipHop for PHP isn't technically a compiler itself. Rather it is a source code transformer. HipHop programmatically transforms your PHP source code into highly optimized C++ and then uses g++ to compile it. HipHop executes the source code in a semantically equivalent manner and sacrifices some rarely used features — such as eval() — in exchange for improved performance. HipHop includes a code transformer, a reimplementation of PHP's runtime system, and a rewrite of many common PHP Extensions to take advantage of these performance optimizations."

The Announcement

"Scaling Facebook is particularly challenging because almost every page view is a logged-in user with a customized experience. 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 write 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."

The Problems Facebook Faced with PHP

  • Can't reuse PHP logic in other systems
  • Extensions are harder to write for PHP developers
  • High CPU usage; can't be as efficient as something like C++
  • Fully impractical to completely rewrite Facebook with a new language

How They Improved It

  • It's a source code transformer
  • Transforms PHP into optimized C++, then compiled with G++
  • Has been in development for over two years.
  • If you've used Facebook within the last six months, you've experience Hip Hop
  • Facebook team have recorded a 50% decrease in CPU usage.
  • They'll have dedicated evangelists to help train/familiarize the community with Hip Hop
  • If you're on a shared host, using Apache, you'll most likely want to continue using standard PHP
  • Where Can We Start Playing with It?

    Hip Hop is available now, and is hosted on Github. You can download it here.

    Hip Hop Process Graph
Related Posts
  • Code
    Web Development
    Componentizing the WebJavascript wide retina preview
    Follow along with Krasimir, learning how to componentize your web applications.Read More…
  • Code
    Mobile Development
    In the Spotlight: Brian LeRouxPreview image@2x
    The explosive growth of the mobile space has accelerated the search for a robust and viable cross-platform solution. In 2008, shortly after the introduction of the iPhone SDK and after fiddling with Cocoa and Objective-C, Brian LeRoux and his colleagues at Nitobi decided that their time was better spent building a cross-platform solution than building native mobile applications.Read More…
  • Code
    Creative Coding
    Using WordPress for Web Application Development: A ReviewApplication foundation 400
    Over the past few months, we've been taking a look at all of the features and aspects that make WordPress a potential foundation for application development. In fact, we've spent roughly 15 articles talking about all that WordPress offers. And though we'll be reviewing each of the points in this email, perhaps the biggest thing to take away that building web applications using WordPress is different than using many of the popular frameworks that are currently available namely because WordPress isn't a framework.Read More…
  • Code
    Mobile Development
    C++ Succinctly: IntroductionPreview image@2x
    C++ Succinctly was written to help professional C# developers learn modern C++ programming. The aim of this series is to leverage your existing C# knowledge in order to expand your skills.Read More…
  • Code
    Creative Coding
    Using WordPress for Web Application Development: Features: SessionsApplication foundation 400
    In this series, we're taking a look at how it's possible to build web applications using WordPress. Thus far, we've talked about how WordPress is a foundation (rather than a framework), its architecture, how we need to conceptually think of it when approaching it especially coming from other languages, and then we began talking about the components that make up a basic web application.Read More…
  • Code
    Theme Development
    Making the Perfect WordPress Theme: Bad PracticesWp white 400
    We discussed how to do good in the previous part of this series: We learn how to write better code, how to comply with the standards, how to make our code readable by others and so on. In this article, we're going to see how to do bad: We'll go through some of the worst practices that one can follow when building WordPress themes.Read More…