what the hack is hhvm?

13
What the HACK is HHVM? Leong Hean Hong 2014-06-06 @ HackerspaceJB

Upload: hean-hong-leong

Post on 17-Jul-2015

114 views

Category:

Technology


1 download

TRANSCRIPT

Page 1: What the HACK is HHVM?

What the HACK is HHVM?Leong Hean Hong

2014-06-06 @ HackerspaceJB

Page 2: What the HACK is HHVM?

About

● Web/mobile developer● Android instructor● Experienced in developing web services● Interest in Linux, web, mobile

Page 3: What the HACK is HHVM?

Agenda

● What is HHVM● Where does HHVM come from?● Why use HHVM?● What is Hack?● Demo (benchmark test)

Page 4: What the HACK is HHVM?

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

Page 5: What the HACK is HHVM?

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

Page 6: What the HACK is HHVM?

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

Page 7: What the HACK is HHVM?

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

Page 8: What the HACK is HHVM?

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)

Page 9: What the HACK is HHVM?

What is Hack?

● Programming language for HHVM● Can mix PHPSome of the features● Static typing● Generics● Collections: Vector, Map, Set, Pair

Page 10: What the HACK is HHVM?

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/

Page 11: What the HACK is HHVM?

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/

Page 12: What the HACK is HHVM?

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/

Page 13: What the HACK is HHVM?

Demo