What the HACK is HHVM?
-
Upload
hean-hong-leong -
Category
Technology
-
view
114 -
download
1
Transcript of What the HACK is HHVM?
What the HACK is HHVM?Leong Hean Hong
2014-06-06 @ HackerspaceJB
About
● Web/mobile developer● Android instructor● Experienced in developing web services● Interest in Linux, web, mobile
Agenda
● What is HHVM● Where does HHVM come from?● Why use HHVM?● What is Hack?● Demo (benchmark test)
What is HHVM?PHP Code
Hack Code
Zend Engine (Interpreter)
HHVM
HipHop Virtual Machine
● PHP execution engine created by Facebook
● Convert PHP to bytecode● Bytecode translated to machine code
at runtime by JIT (just-in-time) compiler
● Similar to .NET/CLR, Java/JVM
JIT
Once upon a time...
● 2008 - Facebook create HPHPc to convert PHP to C++
● Performance boost over Zend PHP● Don’t fully support PHP language● Deployment includes pushing 1GB+ binary
to multiple servers● Need to maintain production+debug builds
the story continues...
● 2010 - Facebook decided to build VM for PHP
● HHVM built on top of HPHPc● 2013 - Facebook.com started running on
HHVM, replacing HPHPc
Why use HHVM?
● Better performance than Zend PHP● Nearly full compatibility with PHP 5.4● 100% support CI, Drupal, Laravel, PHPUnit,
… (http://hhvm.com/frameworks/)
● Supports Hack
Note on using HHVM
● Not available in many Linux repos○ Installation guide: http://bit.ly/1kP9aWS○ Some prebuilt packages provided on GitHub (http:
//bit.ly/1oj3SIK)● Usage with webservers: FastCGI (http://bit.
ly/1xgplGA)● Installation on Mac is unsupported and
experimental (as of 2014-06-06)
What is Hack?
● Programming language for HHVM● Can mix PHPSome of the features● Static typing● Generics● Collections: Vector, Map, Set, Pair
Type Annotation<?hhclass MyClass { const int MyConst = 0; private string $x = ''; public function increment( int $x): int { $y = $x + 1; return $y; }}
// Source: http://hacklang.org/
Generics<?hhclass Box<T> { protected T $data;
public function __construct( T $data) { $this->data = $data; }
public function getData(): T { return $this->data; }}
// Source: http://hacklang.org/
Vector<?hh// Hack introduces new collection types (Vector, Set and Map).function test(): int {
// Vector is preferred over array(1, 2, 3) $vector = Vector {1, 2, 3};
$sum = 0; foreach ($vector as $val) { $sum += $val; }
return $sum;}
// Source: http://hacklang.org/tutorial/
Demo