Hack for HipHop Julien Verlaguet (Facebook) HipHop Team - - PowerPoint PPT Presentation

hack for hiphop
SMART_READER_LITE
LIVE PREVIEW

Hack for HipHop Julien Verlaguet (Facebook) HipHop Team - - PowerPoint PPT Presentation

Hack for HipHop Julien Verlaguet (Facebook) HipHop Team What is PHP good at? PHP features: Very fast installaAon Ame A lot of libraries


slide-1
SLIDE 1

Hack ¡for ¡HipHop ¡

Julien ¡Verlaguet ¡(Facebook) ¡ HipHop ¡Team ¡

slide-2
SLIDE 2

What ¡is ¡PHP ¡good ¡at? ¡

  • PHP ¡features: ¡

– Very ¡fast ¡installaAon ¡Ame ¡ – A ¡lot ¡of ¡libraries ¡ – Easy ¡to ¡learn ¡ – Scales ¡well ¡(avoids ¡concurrency ¡problems) ¡

  • But ¡do ¡we ¡really ¡care? ¡
slide-3
SLIDE 3

PHP: ¡a ¡FAST ¡feedback ¡loop ¡

FAST ¡ dynamic ¡

slide-4
SLIDE 4

PHP: ¡the ¡challenges ¡at ¡scale ¡

  • Performance ¡(runAme): ¡

– At ¡this ¡scale, ¡1% ¡maKers! ¡ – Hard ¡to ¡opAmize ¡

  • Development: ¡

– Refactoring ¡is ¡difficult ¡ – Bugs ¡are ¡caught ¡at ¡runAme ¡ – Tooling ¡is ¡primiAve ¡

slide-5
SLIDE 5

Scaling ¡PHP ¡runAme: ¡HipHop ¡

Compiler ¡C++ (ProducAon) ¡ Interpreter ¡ (Sandboxes) ¡ PHP ¡

slide-6
SLIDE 6

Scaling ¡PHP ¡runAme: ¡HHVM ¡

PHP ¡ JIT ¡Compiler ¡ (HHVM) ¡

slide-7
SLIDE 7

Scaling ¡PHP ¡development: ¡Hack ¡

PHP ¡ JIT ¡Compiler ¡ (HHVM) ¡ HACK ¡

slide-8
SLIDE 8

HACK ¡

(or ¡Hack ¡for ¡HipHop) ¡

slide-9
SLIDE 9

Hack ¡

  • A ¡sta+cally ¡typed ¡language ¡for ¡HHVM ¡
  • CompaAble ¡with ¡PHP: ¡

– Interoperates ¡with ¡no ¡overhead ¡ – Same ¡representaAon ¡at ¡runAme ¡

  • Evolved ¡from ¡PHP: ¡

– If ¡you ¡know ¡PHP, ¡you ¡know ¡Hack! ¡

  • Designed ¡for ¡incremental ¡adop+on: ¡

– Gradual ¡typing ¡

slide-10
SLIDE 10

DEMO ¡

slide-11
SLIDE 11

Hack ¡Type ¡System ¡

  • What ¡must ¡be ¡annotated? ¡

– Class ¡members ¡ – FuncAon ¡parameters ¡ – Return ¡types ¡

  • What ¡is ¡inferred? ¡

– All ¡the ¡rest ¡

  • AnnotaAng ¡is ¡an ¡incremental ¡process ¡
slide-12
SLIDE 12

Hack ¡Types ¡

  • Nullable: ¡?int, ¡?MyClassName ¡
  • Tuples: ¡(int, bool, X)
  • Closures: ¡(function(int): int)
  • CollecAons: ¡Vector<int>, ¡Map<string, int>
  • Generics: ¡A<T>, ¡foo<T>(T $x): T
  • Constraints: ¡foo<T as A>(T $x): T
  • Type ¡aliasing: ¡[new]type t = …
  • Extensible ¡records: ¡shape(‘x’ => int)
slide-13
SLIDE 13

DEMO ¡

slide-14
SLIDE 14

HACK ¡INTERNALS ¡

slide-15
SLIDE 15

Working ¡at ¡scale: ¡Hack ¡

  • We ¡knew ¡we ¡wanted ¡an ¡IDE ¡from ¡day ¡one ¡
  • Big ¡code ¡base ¡
  • The ¡soluAon, ¡a ¡server: ¡

– The ¡server ¡type-­‑checks ¡all ¡the ¡files ¡ – Keeps ¡track ¡of ¡the ¡dependencies ¡ – Recomputes ¡types ¡when ¡something ¡changed ¡

slide-16
SLIDE 16

Working ¡at ¡scale: ¡The ¡Constraints ¡

  • Auto-­‑complete ¡requires ¡very ¡low ¡latency ¡
  • Users ¡use ¡version ¡control ¡(e.g., ¡switching ¡

between ¡branches) ¡

  • We ¡must ¡use ¡a ¡reasonable ¡amount ¡of ¡RAM ¡
  • We ¡must ¡have ¡a ¡reasonable ¡iniAalizaAon ¡Ame ¡
  • Must ¡be ¡stable ¡
slide-17
SLIDE 17

Hack ¡is ¡wriKen ¡in ¡Ocaml! ¡

  • OCaml ¡was ¡a ¡good ¡choice: ¡

– Ideal ¡for ¡symbolic ¡computaAon ¡ – Excellent ¡performance ¡ – Can ¡be ¡compiled ¡to ¡JS ¡ – Interoperates ¡well ¡with ¡C ¡

  • The ¡challenge: ¡

– The ¡runAme ¡doesn’t ¡support ¡mulAcore ¡

slide-18
SLIDE 18

Hack ¡architecture ¡

MASTER ¡ Worker1 ¡ WorkerN ¡ … ¡ SHARED ¡HEAP ¡ C ¡

slide-19
SLIDE 19

OCaml ¡at ¡Scale ¡

  • IPC: ¡

– Pipes, ¡sockets ¡etc ¡… ¡ – Caching ¡layers ¡to ¡avoid ¡deserializaAon ¡cost ¡ – Carefully ¡crabed ¡lock ¡free ¡data ¡structures ¡(C ¡code) ¡

  • Garbage ¡collecAon: ¡

– Workers ¡keep ¡a ¡small ¡heap ¡ – Shared ¡memory ¡is ¡compacted ¡by ¡the ¡master ¡

  • OCaml ¡makes ¡you ¡think ¡hard ¡about ¡shared ¡
  • bjects: ¡

– And ¡that’s ¡a ¡good ¡thing! ¡;-­‑) ¡

slide-20
SLIDE 20

QuesAons? ¡