HHVM  

Hack  

Scaling  PHP-­‐based  Development   with  HHVM  and  Hack      June  22nd,  2016                                                                                                                                                              Drew  Paroski  

Speaker  Bio   •  MemSQL  (2015-­‐present)   – OpJmized-­‐SQL  à  x64  codegen   – Programming  language  feature   development  

•  Facebook  (2009-­‐2015)   – HipHop  for  PHP   – HHVM   – Hack  

What  is  HHVM?   •  HHVM  =  HipHop  Virtual  Machine   •  Executes  programs  wriUen  in  PHP  or  Hack

 

 

•  Uses  JIT  compilaJon  for  superior  performance   while  preserving  producJve  edit-­‐save-­‐run  flow  

 

•  Used  in  producJon  by  3  of  the  top  10  websites   in  the  world   •  Can  run  most  PHP  applicaJons  out  of  the  box

 

 

•  Open  source:  github.com/facebook/hhvm  

What  is  Hack?   •  Hack  is  a  new  programming  language  for   HHVM    

•  Gradually-­‐typed   •  Interoperates  seamlessly  with  PHP   •  Provides  an  advanced  type-­‐checker  to   improve  developer  producJvity •  Adds  many  new  language  features •  Open  source:  github.com/facebook/hhvm    

 

 

 

 

Outline   •  Ge#ng  started  with  HHVM  and  Hack   •  BoosJng  applicaJon  performance  with   HHVM •  Improving  developer  producJvity  with   Hack •  Asynchronous  I/O  with  Hack •  New  features  since  Hack’s  iniJal  release   •  Impact  on  the  community    

 

 

 

 

 

 

Gedng  started   •  I  want  to  try  out  HHVM  and  Hack,  how  do  I   get  started?  

 

•  My  environment:  Macbook  (Mac  OS  X  10.11)   with  a  VM  running  Linux  (Ubuntu  14.04)  

 

•  Let’s  google  “install  hhvm  ubuntu  14.04”  

Quick  install   > sudo apt-key adv --recv-keys –keyserver \
 hkp://keyserver.ubuntu.com:80 \
 0x5a16e7281be7a449
 
 > sudo add-apt-repository \
 "deb http://dl.hhvm.com/ubuntu trusty main"
 
 > sudo apt-get update
 
 > sudo apt-get install hhvm

Launch  the  Hack  type-­‐checker   •  Go  to  the  root  directory  of  your  code  base

 

 

•  Run  the  following  commands:

 

 

> touch .hhconfig
 


> hh_client

Outline   •  Gedng  started  with  HHVM  and  Hack   •  Boos6ng  applica6on  performance  with   HHVM •  Improving  developer  producJvity  with   Hack •  Asynchronous  I/O  with  Hack •  New  features  since  Hack’s  iniJal  release   •  Impact  on  the  community    

 

 

 

 

 

 

Command  line  example  with  HHVM   # Create a PHP source file
 


> echo \
 ' fib.php



 # Execute fib.php with HHVM
 > hhvm fib.php

Command  line  example  with  HHVM   # Run HHVM global analysis on fib.php
 


> hhvm --hphp -t hhbc -i fib.php -o .
 # Execute fib.php with global optimizations
 > hhvm -v Repo.Central.Path=hhvm.hhbc \
 -v Repo.Authoritative=true fib.php


Simple  Micro-­‐Benchmark  Demo  

Micro-­‐Benchmarks   •  Benchmarks  are  fun,  but  they  can  be  misleading

 

 

•  What  people  really  care  about  is  applica6on   performance  

 

•  Most  real  applicaJons  do  a  fair  amount  of  I/O,   which  JIT  compilaJon  can’t  speed  up  for  you  

 

•  Rule  of  thumb:  Always  measure  to  see  how   your  applicaJon  performs  on  stock  PHP  vs   HHVM  

Kinsta’s  applicaJon  benchmarks   kinsta.com/blog/the-­‐definiJve-­‐php-­‐7-­‐final-­‐version-­‐hhvm-­‐benchmark/  

Kinsta’s  applicaJon  benchmarks   kinsta.com/blog/the-­‐definiJve-­‐php-­‐7-­‐final-­‐version-­‐hhvm-­‐benchmark/  

Who  uses  HHVM  in  producJon?   •  Major  websites:   –   Facebook   –   Baidu   –   Wikipedia   –   Etsy   –   Box    …  

Who  uses  HHVM  in  producJon?   •  HosJng  services:   –   heroku.com   –   bitnami.com   –   a2hosJng.com   –   openshin.com   –   servergrove.com    …  

Outline   •  Gedng  started  with  HHVM  and  Hack   •  BoosJng  applicaJon  performance  with   HHVM •  Improving  developer  produc6vity  with   Hack •  Asynchronous  I/O  with  Hack •  New  features  since  Hack’s  iniJal  release   •  Impact  on  the  community    

 

 

 

 

 

 

Install  Nuclide  IDE  (opJonal)   hUps://nuclide.io/docs/features/remote/  

Install  Nuclide  IDE  (opJonal)   # Install Node 6.2.1 on my Ubuntu Linux VM
 


> > > > > >

wget https://nodejs.org/dist/v6.2.1/node-v6.2.1.tar.gz
 tar -xvf node-v6.2.1.tar.gz
 cd node-v6.2.1
 ./configure
 make
 sudo make install



 # Install watchman on my Ubuntu Linux VM
 


> > > > > > >

git clone https://github.com/facebook/watchman.git cd watchman git checkout v4.5.0
 ./autogen.sh
 ./configure
 make
 sudo make install

Hack  Autocomplete  Demo   with  Nuclide  

Outline   •  Gedng  started  with  HHVM  and  Hack   •  BoosJng  applicaJon  performance  with   HHVM •  Improving  developer  producJvity  with   Hack •  Asynchronous  I/O  with  Hack •  New  features  since  Hack’s  iniJal  release   •  Impact  on  the  community    

 

 

 

 

 

 

Asynchronous  I/O  with  Hack   •  JIT  compilaJon  can’t  speed  up  I/O  for  you •  Async  I/O  APIs  can  be  used  to  reducing  the   amount  of  Jme  the  applicaJon  blocks  on  I/O •  In  pracJce,  changing  an  exisJng  applicaJon   to  use  async  I/O  APIs  is  onen  difficult •  Hack’s  async/await  feature  makes  it  easy  to   use  async  I/O  APIs  and  improve  applicaJon   performance    

 

 

 

 

 

Async  I/O  Demo  

Async/await   •  async/await  provides  a  clean  way  to  perform   cooperaJve  mulJ-­‐tasking  on  a  single  thread •  async/await  does  not  involve  mulJ-­‐threading •  When  invoked,  an  async  funcJon  will  execute   as  far  as  it  can  unJl  it  returns  or  it  “awaits”  on   an  Awaitable  whose  result  is  not  available  yet •  The  caller  of  an  async  funcJon  receives  an   Awaitable  that  represents  the  async  funcJon’s   return  value    

 

 

 

 

 

Async/await   •  When  an  async  funcJon  “awaits”  on  an   Awaitable  whose  result  is  not  available   yet,  the  async  funcJon’s  stack  frame  is   “suspended”  and  moved  off  the  call  stack •  At  some  point  aner  the  Awaitable’s  result   becomes  available,  the  suspended  stack   frame  will  be  “restored”  and  put  back  on   the  call  stack,  and  execuJon  of  the  async   funcJon  will  resume  where  it  len  off    

 

Async/await   Call  stack  

 

Suspended  frames  

Output  

Async/await   Call  stack   fetchAll()  
 

Suspended  frames  

Output  

Async/await   Call  stack   fetch("hhvm.com")   fetchAll()  
 

Suspended  frames  

Output   Begin fetching http://hhvm.com

Async/await   Call  stack  

Output   Begin fetching http://hhvm.com

fetchAll()  
 

Suspended  frames   fetch("hhvm.com")  

Async/await   Call  stack   fetch("www.example.com")   fetchAll()  
 

Suspended  frames   fetch("hhvm.com")  

Output   Begin fetching http://hhvm.com
 Begin fetching http://www.example.com

Async/await   Call  stack  

Output   Begin fetching http://hhvm.com
 Begin fetching http://www.example.com

fetchAll()  
 

Suspended  frames   fetch("hhvm.com")   fetch("www.example.com")  

Async/await   Call  stack  

Output   Begin fetching http://hhvm.com
 Begin fetching http://www.example.com

 

Suspended  frames   fetch("hhvm.com")   fetch("www.example.com")   fetchAll()  

Async/await   Call  stack  

Output   Begin fetching http://hhvm.com
 Begin fetching http://www.example.com

 
 

Suspended  frames   fetch("hhvm.com")   fetch("www.example.com")   fetchAll()  

Async/await   Call  stack   fetch("www.example.com")    
 

Suspended  frames   fetch("hhvm.com")   fetchAll()  

Output   Begin fetching http://hhvm.com
 Begin fetching http://www.example.com
 Done fetching http://www.example.com

Async/await   Call  stack    
 

Suspended  frames   fetch("hhvm.com")   fetchAll()  

Output   Begin fetching http://hhvm.com
 Begin fetching http://www.example.com
 Done fetching http://www.example.com

Async/await   Call  stack   fetch("hhvm.com")    
 

Suspended  frames   fetchAll()  

Output   Begin fetching http://hhvm.com
 Begin fetching http://www.example.com
 Done fetching http://www.example.com
 Done fetching http://hhvm.com

Async/await   Call  stack    
 

Suspended  frames   fetchAll()  

Output   Begin fetching http://hhvm.com
 Begin fetching http://www.example.com
 Done fetching http://www.example.com
 Done fetching http://hhvm.com

Async/await   Call  stack   fetchAll()    
 

Suspended  frames  

Output   Begin fetching http://hhvm.com
 Begin fetching http://www.example.com
 Done fetching http://www.example.com
 Done fetching http://hhvm.com

Async/await   Call  stack  

Output   Begin fetching http://hhvm.com
 Begin fetching http://www.example.com
 Done fetching http://www.example.com
 Done fetching http://hhvm.com

 

Suspended  frames  

0: http://hhvm.com
 13897 bytes
 1: http://www.example.com
 1270 bytes

Outline   •  Gedng  started  with  HHVM  and  Hack   •  BoosJng  applicaJon  performance  with   HHVM •  Improving  developer  producJvity  with   Hack •  Asynchronous  I/O  with  Hack •  New  features  since  Hack’s  ini6al   release   •  Impact  on  the  community    

 

 

 

 

 

 

New  language  features   •  All  major  PHP  7  language  features:   – Null  coalescing  operator:  ?? – Spaceship  operator:  <=> – Support  for  declare(strict_types=1) – Group  use  declaraJons   – Universal  variable  syntax   – Generator  return  expressions   – Generator  delegaJon  

 

•  Improved  type-­‐checker  coverage  

New  language  features   •  Async  closures  and  async  lambdas   •  Immediately-­‐executed  async  lambdas   •  Async  generators  /  foreach  await   •  Interface  requirements   •  Abstract  constants   •  Abstract  final  classes   •  Run  Jme  enforcement  of  return  type   annotaJons  on  async  funcJons  

New  language  features   •  Type  constants   •  Super  constraints  on  typevars   •  Magic  classname  type  and   <<__ConsistentConstruct>>  aUribute •  Nullsafe  access  operator:  ?-> •  XHP  aUribute  access  operator:  ->: •  Pipe  operator:  |> •  New  Hack  array  types:  vec and dict

 

 

 

Async  closures  and  async  lambdas   •  Async  closures:   
 async function(..) { .. }

•  Async  closures: async (..) ==> ..

Immediately-­‐executed  async  lambdas   •  Syntax:   


async { .. }

     Equivalent  to: (async () ==> { .. })()

Async  generators   •  An  “async  generator”  is  an  async  funcJon   that  contains  a  “yield”  expression  in  its  body
 


async function series($n)
 {
 $obj = await fetchObj($n);
 foreach ($obj->items as $x) {
 yield processItem($x);
 }
 }

Foreach  await   •  The  “foreach  await”  feature  can  be  used  to   loop  over  the  values  produced  by  an  async   generator:
 


async function series($n) { .. }
 


async function processSeries($n)
 {
 foreach (series($n) await as $x) {
 doSomething($x);
 }
 }

Super  constraints  on  typevars   •  “super”  constraints  on  typevars  are  the   converse  of  “as”  constraints:
 


class C
 {
 public function
 __construct(public array $a) { }
 


}

public function
 concat(C $obj): C
 {
 $res = array();
 foreach ($this->a as $x) $res[] = $x;
 foreach ($obj->a as $x) $res[] = $x;
 return new C($res); // <- type error
 }


Super  constraints  on  typevars   •  “super”  constraints  on  typevars  are  the   converse  of  “as”  constraints:
 


class C
 {
 public function
 __construct(public array $a) { }
 


}

public function
 concat(C $obj): C
 {
 $res = array();
 foreach ($this->a as $x) $res[] = $x;
 foreach ($obj->a as $x) $res[] = $x;
 return new C($res);
 }


classname    and    <<__ConsistentConstruct>>  

•  The  classname  value  is  a  special  kind   of  string  value  that  is  known  to  refer  to   some  class  which  is  T  or  a  subtype  of  T: 


class C
 {
 public function __construct() { }
 }
 


function create(string $c): T
 {
 return new $c(); // <- type error
 }

classname    and    <<__ConsistentConstruct>>  

•  The  classname  value  is  a  special  kind   of  string  value  that  is  known  to  refer  to   some  class  which  is  T  or  a  subtype  of  T: 


<<__ConsistentConstruct>>
 class C
 {
 public function __construct() { }
 }
 


function create(classname $c): T
 {
 return new $c();
 }

Pipe  operator   •  Example:   


$posts
 |> array_map($p ==> $p->getAuthor(), $$)
 |> array_filter( $$, $u ==> $u->isFriendsWith($user))

     Equivalent  to: 


array_filter( array_map($p ==> $p->getAuthor(), $posts), $u ==> $u->isFriendsWith($user))

New  tools  and  APIs   •  hh_format   –  Hack  source  formaUer

 

 

•  h2tp  transpiler   –  Hack  -­‐>  PHP  converter

 

 

•  New  async  I/O  APIs   –  Async  MySQL   –  Async  stream_select()  API  

Outline   •  Gedng  started  with  HHVM  and  Hack   •  BoosJng  applicaJon  performance  with   HHVM •  Improving  developer  producJvity  with   Hack •  Asynchronous  I/O  with  Hack •  New  features  since  Hack’s  iniJal  release   •  Impact  on  the  community    

 

 

 

 

 

 

Impact  on  the  community   •  CompeJJon  is  a  good  thing

 

 

•  HHVM  demonstrated  that  a  significant   porJon  of  PHP  users  care  about  run   Jme  performance  

 

•  Hack  demonstrated  the  importance  of   type  safety  for  larger,  more  mature  PHP   codebases  

Impact  on  the  community   •  HHVM  has  made  some  of  the  largest   websites  snappier  and  more  responsive    

•  HHVM  was  almost  certainly  one  of  the   main  reasons  that  PHP7  development   focused  on  improving  performance  

 

•  HHVM  drove  the  creaJon  of  a  formal   specificaJon  for  the  PHP  language  

Impact  on  the  community   •  Hack’s  language  features  have  noJceably   influenced  new  features  in  stock  PHP:   –  Generators   –  Scalar  type  annotaJons   –  Return  type  annotaJons   –  Nullable  type  annotaJons

 

 

•  The  swin  pace  of  Hack’s  evoluJon  helped   moJvate  the  PHP  community  to  improve   the  stock  PHP  language  

Thank  you!  

HHVM   HHVM  Website:   Hack  Website:   Github:  

hhvm.com   hacklang.org   github.com/facebook/hhvm  

Hack  

Hack and HHVM Webinar Slides.pdf

Page 3 of 76. Speaker Bio. • MemSQL (2015-present). – OpJmized-SQL à x64 codegen. – Programming language feature. development. • Facebook (2009-2015). – HipHop for PHP. – HHVM. – Hack. Page 3 of 76 ...

6MB Sizes 1 Downloads 113 Views

Recommend Documents

Webinar Series
developer across most hardware platforms and versions of Oracle. ... providing a solid foundation for all technologies that are built on top of it. .... Networking: Internal firewalls, TNS, Listeners, embedded gateway, apache and IIS..............10.

Webinar Series -
Session 5 | “There will always remain blind spots... learning to act under uncertainty”. The fifth and last webinar session of our series focuses on the “blind spots” ...

Webinar announcement.pdf
Katerina Zourou, Ph.D., is a researcher in the field of computer supported collaborative. language learning and owner of Web2Learn, Greece. She is project ...

Webinar 1 - Highlights.pdf
There was a problem previewing this document. Retrying... Download. Connect more apps... Try one of the apps below to open or edit this item. Main menu.

Homeownership Webinar Handouts.pdf
or condo operating charges or maintenance. fees. Land lease payments (in certain cases). The Process. Page 3 of 32. Homeownership Webinar Handouts.pdf.

EIV Webinar Handouts.pdf
Interpreting Data. ◦ How to Calculate Income and Expenses. ◦ Existing Tenant and Debts Owed Reports. Other Income Reports. ◦ CBMS, Child Support/FSR, ...

Tools webinar presentation.pdf
There was a problem previewing this document. Retrying... Download. Connect more apps... Try one of the apps below to open or edit this item. Tools webinar ...

PDF-Webinar-AllAboutOBM.pdf
Page 4 of 10. Key Terms in Open Book. AlL abOut Open boOk ManAgemENt. • Scoreboard: A whiteboard that displays the current. and forecasted performance ...

Webinar.11.18.2016.Youth and Problem Gambling.pdf
There was a problem previewing this document. Retrying... Download. Connect more apps. ... Youth and Problem Gambling.pdf. Webinar.11.18.2016.Youth and ...

Enpr-EMA awareness webinar - European Medicines Agency
Nov 15, 2016 - conference window. Please ensure ... full international format and click Join to receive a call from the system (you will be automatically muted).

PPT-Webinar-TimeManagement-March2016.pdf
8th / early 9th century – modern clocks make meaningful. appearances in the Middle East (Iraq). • 11th century – clock mechanisms are well in use, mostly ...

USAID Water Office Webinar Series Flyer.pdf
Jun 18, 2015 - For registration information as well as links to past recordings, visit ... this USAID webinar website shortly after each event. Brought to you by ...

Medical Expense and Calculation Webinar Handouts.pdf
There was a problem previewing this document. Retrying... Download ... Medical Expense and Calculation Webinar Handouts.pdf. Medical Expense and ...

Hack Madden Mobile With No Human Verification Hack ...
Neco Inc., of Denver, Colorado, provides 3D Computer Aided Design and support services ... Generator Madden Mobile Hack No Survey Kindle Fire Free Game ... Survey Live Free Game Generator Codes on Apple TV, Code Generator ...

Fifa 17 Hack Generator 799 @* Fifa 17 Hack Mobile Android
Live Free Game Generator Codes online, Free Game Generator Codes Fifa 17 Hack Coins Android CentralCode Generator Fifa 17. Free Coins No Verification ...

Cross-College-Collaboration-Webinar-Registration-Responses.pdf ...
Page 1 of 1. Cross-College-Collaboration-Webinar-Registration-Responses.pdf. Cross-College-Collaboration-Webinar-Registration-Responses.pdf. Open.

RainToday.com - Webinar Campaign Helps Global ... - F5 Networks
To complement emails it planned to send to its install base, F5 encouraged its ... .f5.com/news-press-events/web-media/webcasts/impact-in-ssl-processing.html.

PDF-Webinar-ServantLeadership-February2016.pdf
Robert Greenleaf. Servant Leadership. Page 4 of 23. PDF-Webinar-ServantLeadership-February2016.pdf. PDF-Webinar-ServantLeadership-February2016.pdf.

PPT-Webinar-ServiceTips-June2017.pdf
Whoops! There was a problem loading more pages. Retrying... Whoops! There was a problem previewing this document. Retrying... Download. Connect more ...

Social Media Draft Guidance Webinar - FDA
Jul 10, 2014 - Jean-Ah Kang – Internet/Social Media Platforms with Character ... educational grant) and has no control or influence on the third-party site. 10 ...

Aidala Fullilove housing webinar slides.pdf
... of Health and Human Services (HHS) under grant number UB6HP27878-01-00, Affordable Care Act ... 1 of 10 Regional PHTC funded by HRSA ... Enhance the public health workforces' ability to effectively deliver the Essential Public Health.