2010/HipHop for PHP
HipHop transforms PHP source code into highly optimised C++ and then compiles it using g++. It allows developers to continue writing complex logical directly with PHP but leverages the speed benefits of using C++. Currently, HipHop powers the majority of Facebook servers, making this more than just a theoretical exercise.
This session will cover how HipHop works, how to setup HipHop and the small changes that may be required to applications to allow it to work with both PHP and HipHop.
Speaker: Haiping Zhao
Return to this session's details
Two major differences between PHP and C++: dynamic dispatch versus static dispatch and weak versus strong types.
Conversion to C++ is not that helpful for code portions that use highly dynamic features. But most PHP code does not use those features.
Build a big symbol table from PHP code and use static analysis to try to determine types for variables. Pick the most specific types possible for every variable.
Code generation yields more optimizations than JIT compilation.
'eval' is evil - makes static analysis more difficult.
Slab allocation is less memory efficient than malloc() - but is much faster. This can be good for short-lived values.
Runtime uses reference counting to manage memory. Reference cycles can lead to memory leaks, so memory is sweeped clear after each web request.
Code generation cuts hardware requirements in half.
One-to-one mappings between PHP and C++ where possible. The goal is to allow C++ apps to call into converted PHP functions. Even PHP exceptions map to C++ exceptions.