hack for hiphop
play

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


  1. Hack ¡for ¡HipHop ¡ Julien ¡Verlaguet ¡(Facebook) ¡ HipHop ¡Team ¡

  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? ¡

  3. PHP: ¡a ¡FAST ¡feedback ¡loop ¡ dynamic ¡ FAST ¡

  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 ¡

  5. Scaling ¡PHP ¡runAme: ¡HipHop ¡ PHP ¡ Interpreter ¡ Compiler ¡C++ (Sandboxes) ¡ (ProducAon) ¡

  6. Scaling ¡PHP ¡runAme: ¡HHVM ¡ PHP ¡ JIT ¡Compiler ¡ (HHVM) ¡

  7. Scaling ¡PHP ¡development: ¡Hack ¡ HACK ¡ PHP ¡ JIT ¡Compiler ¡ (HHVM) ¡

  8. HACK ¡ (or ¡Hack ¡for ¡HipHop) ¡

  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 ¡

  10. DEMO ¡

  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 ¡

  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)

  13. DEMO ¡

  14. HACK ¡INTERNALS ¡

  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 ¡

  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 ¡

  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 ¡

  18. Hack ¡architecture ¡ MASTER ¡ Worker1 ¡ … ¡ WorkerN ¡ C ¡ SHARED ¡HEAP ¡

  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 ¡ objects: ¡ – And ¡that’s ¡a ¡good ¡thing! ¡;-­‑) ¡

  20. QuesAons? ¡

Download Presentation
Download Policy: The content available on the website is offered to you 'AS IS' for your personal information and use only. It cannot be commercialized, licensed, or distributed on other websites without prior consent from the author. To download a presentation, simply click this link. If you encounter any difficulties during the download process, it's possible that the publisher has removed the file from their server.

Recommend


More recommend