Slide 1

Slide 1 text

No content

Slide 2

Slide 2 text

asm89 / @iam_asm89

Slide 3

Slide 3 text

No content

Slide 4

Slide 4 text

No content

Slide 5

Slide 5 text

History

Slide 6

Slide 6 text

No content

Slide 7

Slide 7 text

HPHPc ● Open-sourced 2010 ● 6x speedup vs Zend VM

Slide 8

Slide 8 text

HPHPc ● Compiled PHP C++ →

Slide 9

Slide 9 text

HPHPc ● No eval ● No dynamic functions ● Two execution engines

Slide 10

Slide 10 text

No content

Slide 11

Slide 11 text

JIT compiler

Slide 12

Slide 12 text

JIT compiler ● Zend VM – PHP Opcodes Runs on VM → →

Slide 13

Slide 13 text

JIT compiler ● HHVM – PHP HHBC (ByteCode) HHIR (Intermediate Representation) → → Machine code →

Slide 14

Slide 14 text

Getting started

Slide 15

Slide 15 text

$ sudo wget -O - http://dl.hhvm.com/conf/hhvm.gpg.key \ > | sudo apt-key add - $ echo deb http://dl.hhvm.com/ubuntu trusty main \ > | sudo tee /etc/apt/sources.list.d/hhvm.list $ sudo apt-get update $ sudo apt-get install hhvm https://github.com/facebook/hhvm/wiki/Prebuilt-packages-on-Ubuntu-14.04

Slide 16

Slide 16 text

Homebrew https://github.com/facebook/hhvm/wiki/Building-and-installing-HHVM-on-OSX-10.9

Slide 17

Slide 17 text

fastcgi https://github.com/facebook/hhvm/wiki/FastCGI

Slide 18

Slide 18 text

$ hhvm hi-dpc.php hi dpc!

Slide 19

Slide 19 text

Can I run HHVM?

Slide 20

Slide 20 text

http://hhvm.com/frameworks/

Slide 21

Slide 21 text

Try it!

Slide 22

Slide 22 text

Why HHVM?

Slide 23

Slide 23 text

Not just PHP...

Slide 24

Slide 24 text

What is at stake? ● Consequence of subtle bugs: – Corrupt database, etc.. ● Consequence of difficult APIs: – Copy pasta, $needle or $haystack first ● Consequence of difficult refactoring – Bad APIs stay bad

Slide 25

Slide 25 text

Technical debt

Slide 26

Slide 26 text

No content

Slide 27

Slide 27 text

No content

Slide 28

Slide 28 text

● A statically typed language for HHVM ● Compatible with PHP: – Interoperates with no overhead – Same representation at runtime ● Evolved from PHP: – If you know PHP, you know Hack! ● Designed for incremental adoption: – Gradual typing

Slide 29

Slide 29 text

No content

Slide 30

Slide 30 text

No content

Slide 31

Slide 31 text

Demo

Slide 32

Slide 32 text

Hack type system ● What must be annotated? – Class members – Function parameters – Return types The rest is inferred

Slide 33

Slide 33 text

Hack types ● All PHP types: int, MyClassName, array ● Nullable: ?int, ?MyClassName ● Mixed: anything (careful) ● Tuples: (int, bool, X) ● Closures: (function(int): int) ● Collections: Vector, Map ● Generics: A, foo(T $x): T ● Constraints: foo(T $x): T

Slide 34

Slide 34 text

Not just types

Slide 35

Slide 35 text

Type annotations at run time function foo(int $x): void { .. } foo('baz'); // Output Fatal error: Expected int, string given function bar(): bool { return 3.14; } // Output Fatal error: Expected bool, float given

Slide 36

Slide 36 text

λ expressions

Slide 37

Slide 37 text

PHP closure expressions // PHP closure syntax $b = 42; $fn = function($a) use ($b) { return $a + $b; }; $x = $fn(42);

Slide 38

Slide 38 text

Hack lambda expressions // PHP closure syntax $b = 42; $fn = function($a) use ($b) { return $a + $b; }; $x = $fn(42); // Hack lambda syntax $b = 42; $fn = $a ==> $a + $b; $x = $fn(42);

Slide 39

Slide 39 text

Benefits of Lambda Expressions ● More concise ● Auto capturing references ● Makes it easier to use callback-based APIs (wait for it..)

Slide 40

Slide 40 text

Collections

Slide 41

Slide 41 text

The Hack Collections framework is a set of language features and APIs that serve as a complete alternative to PHP arrays // PHP arrays $a = array(1, 2, 3); $b = array('a' => 4, 'b' => 5); function foo(array $c): void { .. } // Hack collections $a = Vector {1, 2, 3}; $b = Map {'a' => 4, 'b' => 5}; function foo(Map $c): void { .. }

Slide 42

Slide 42 text

Map/filter example // PHP arrays $x = array_filter(array_map($fn1, $a), $fn2);

Slide 43

Slide 43 text

Map/filter example // PHP arrays $x = array_filter(array_map($fn1, $a), $fn2); // Hack collections $x = $a->map($fn1)->filter($fn2);

Slide 44

Slide 44 text

Map/filter example // PHP arrays $x = array_filter( array_map( function($a) use ($b) { return $a + $b; }, $array ), function($a) { return $a > 10; } );

Slide 45

Slide 45 text

Map/filter example // PHP arrays $x = array_filter( array_map( function($a) use ($b) { return $a + $b; }, $array ), function($a) { return $a > 10; } ); // Hack collections $x = $a->map($a ==> $a + $b) ->filter($a ==> $a > 10);

Slide 46

Slide 46 text

Demo

Slide 47

Slide 47 text

More features ● Async/await ● Constructor promotion ● Trailing comma's in function calls ● Trait requirements ● User attributes (<> class C {}) ● <> ● ...

Slide 48

Slide 48 text

Try it!

Slide 49

Slide 49 text

https://github.com/facebook/hhvm #hhvm @ freenode IRC

Slide 50

Slide 50 text

@iam_asm89 https://joind.in/10863