Upgrade to Pro — share decks privately, control downloads, hide ads and more …

What the HACK is HHVM?

What the HACK is HHVM?

Brief introduction of Facebook's HHVM. It includes description of Hack features, and features. I presented this in HackerspaceJB in 2014.

#facebook #programming #hsjb #johor

Leong Hean Hong

June 06, 2014
Tweet

More Decks by Leong Hean Hong

Other Decks in Programming

Transcript

  1. About • Web/mobile developer • Android instructor • Experienced in

    developing web services • Interest in Linux, web, mobile
  2. Agenda • What is HHVM • Where does HHVM come

    from? • Why use HHVM? • What is Hack? • Demo (benchmark test)
  3. 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
  4. 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
  5. 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
  6. 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
  7. 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)
  8. What is Hack? • Programming language for HHVM • Can

    mix PHP Some of the features • Static typing • Generics • Collections: Vector, Map, Set, Pair
  9. Type Annotation <?hh class MyClass { const int MyConst =

    0; private string $x = ''; public function increment( int $x): int { $y = $x + 1; return $y; } } // Source: http://hacklang.org/
  10. Generics <?hh class Box<T> { protected T $data; public function

    __construct( T $data) { $this->data = $data; } public function getData(): T { return $this->data; } } // Source: http://hacklang.org/
  11. 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/