3. HHVM is not a source code transformer
That was HPHPc, it’s dead.
▪ Runs your PHP pages live,
just like PHP
▪ Uses a builtin web server
or FastCGI – Runs anywhere
(on 64-bit x86 linux)
▪ Drop-in replacement for PHP
(mostly)
Webserver
(apache, nginx, etc…)
Database
(mysql, posges,
mongo, redis, etc…)
cart.phphome.phplogin.php
index.php
PHP
A
P
C
4. HHVM is not a source code transformer
That was HPHPc, it’s dead.
▪ Runs your PHP pages live,
just like PHP
▪ Uses a builtin web server
or FastCGI – Runs anywhere
(on 64-bit x86 linux)
▪ Drop-in replacement for PHP
(mostly)
Webserver
(apache, nginx, etc…)
Database
(mysql, posges,
mongo, redis, etc…)
cart.phphome.phplogin.php
index.php
HHVM
Just Plug and Pray!
Erm, I mean… Play
5. HHVM supports (most) PHP syntax
Tracking HEAD
▪ Pending: Splat (5.6)
(Variadics work already)
▪ Finally
▪ Generators
▪ Namespaces
And some of its own
▪ Scalar type hint
(and much much more)
▪ Async co-routines
▪ Generics
▪ Collections (smart arrays)
▪ XHP (Integrated XHTML)
▪ User Attributes
6. HHVM’s Parity Gap
• Only about 60% of PHP’s unit tests pass.
• 20 top framework (and more) do pass.
• So I wouldn’t sweat the small stuff.
7. HHVM is easy to install
If you’re on Ubuntu
▪ deb http://dl.hhvm.com/ubuntu saucy main
▪ apt-get update
▪ apt-get install hhvm (or hhvm-nightly)
▪ Provides one binary covering cli, fcgi server, and libevent server
▪ Coming very soon to a Debian near you!
Or something Debianish…
8. HHVM is buildable
On other linux distros (MacOSX in interp mode only)
• http://hhvm.com/repo/wiki
• gcc 4.8 or later (soon to be 4.8 or later)
• Boost 1.49 or later
• Lots of other dependencies….
• git clone git@github.com:facebook/hhvm
cmake .
make –j
• hphp/hhvm/hhvm
xkcd.org/303
9. Running a server
Built-in HTTP server FastCGI
Server {
Port = 80
Type = libevent
SourceRoot = /var/www
}
Log {
Level = Error
UseLogFile = true
File = /var/log/hhvm-error.log
Access { * {
File = /var/log/hhvm-access.log
Format = %h %l %u %t ”%r” %>s %b
}}
}
VirtualHost {
…}
StaticFile {
…}
Server {
Port = 9000
Type = fastcgi
SourceRoot = /var/www
}
Log {
Level = Error
UseLogFile = true
File = /var/log/hhvm-error.log
Access { * {
File = /var/log/hhvm-access.log
Format = %h %l %u %t ”%r” %>s %b
}}
}
Requires patched libevent
10. Running a FastCGI server
nginx HHVM
server {
server_name www.example.com;
root /var/www;
index index.php;
location ~ .php$ {
fastcgi_pass unix:/var/run/hhvm.sock
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME
/var/www$fastcgi_script_name;
include fastcgi_param;
}
}
Server {
FileSocket = /var/run/hhvm.sock
Type = fastcgi
SourceRoot = /var/www
}
Log {
Level = Error
UseLogFile = true
File = /var/log/hhvm-error.log
Access { * {
File = /var/log/hhvm-access.log
Format = %h %l %u %t ”%r” %>s %b
}}
}
11. HPHPC in 2010 - 2011
• Crazy cross compiler.
• Converts php to C++.
HHVM in 2013
• Complete new VM.
• Facebook is running it on Production.
• Great community, over 750 pull requests.
13. HHVM – Bytecode interpreter
• PHP5 style bytecode execution
• APC-like caching of bytecodes
• Perf about on par with PHP
Modified?
Invalidate
Cache
Compile to
Bytecode
Run
Bytecode
Y
N
14. HHVM – Native code JIT
• Bytecodes run a few times “cold”
• Variable type inference
• Hotpath detection
• Transform to native code
Modified?
Invalidate
Cache
Compile to
Bytecode
Have native?
Run Native
Hot?
Run
Bytecode
Compile to
Native
Y
Y
Y
N
N
N
16. HHVM – Repo Authoritative Mode
• “Production Mode”
• Improved offline pre-analysis
• Assumes no changes
• Another 10% or so perf gain
PreCompil
e Bytecode
Have native?
Run Native
Hot?
Run
Bytecode
Compile to
Native
Y
Y
N
N
Facebook started to work on HipHop for PHP in 2008. Their goal was to speed up the PHP execution speed and the first version of the project was composed of the tandem HPHPc/HPHPi. HPHPc is a PHP to C++ transpiler which was used to deploy the code to the production servers while HPHPi was an interpreter used during development and debug stages.
HPHPc did a good job on improving performance but it was not without issues: maintaining both HPHPc and HPHPi in sync proved to be cumbersome plus some differences still existed between the transpiled code vs the interpreted one. That's why back in 2010 Facebook decided to go for another approach and created HHVM – a new virtual machine designed to replace the Zend Engine used by PHP. By the end of 2012 HHVM achieved performance parity with the former HPHPc and soon surpassed it.
Facebook started to work on HipHop for PHP in 2008. Their goal was to speed up the PHP execution speed and the first version of the project was composed of the tandem HPHPc/HPHPi. HPHPc is a PHP to C++ transpiler which was used to deploy the code to the production servers while HPHPi was an interpreter used during development and debug stages.
HPHPc did a good job on improving performance but it was not without issues: maintaining both HPHPc and HPHPi in sync proved to be cumbersome plus some differences still existed between the transpiled code vs the interpreted one. That's why back in 2010 Facebook decided to go for another approach and created HHVM – a new virtual machine designed to replace the Zend Engine used by PHP. By the end of 2012 HHVM achieved performance parity with the former HPHPc and soon surpassed it.
Rather than directly interpret or compile PHP code directly to C++, HHVM compiles Hack and PHP into an intermediate bytecode. This bytecode is then translated into x64 machine code dynamically at runtime by a just-in-time (JIT) compiler. This compilation process allows for all sorts of optimizations that cannot be made in a statically compiled binary, thus enabling higher performance of your Hack and PHP programs.
Okay to mention that we’re about to move to github.com/hhvm/hhvm
This slide isn’t meant to be readable. It just illustrates how onerous writing an extension function for PHP can be.