HHVM: A High Performance PHP Engine

B9c0f8666d9163c05e0db3eaf781fb21?s=47 Reeze Xia
February 03, 2015

HHVM: A High Performance PHP Engine

B9c0f8666d9163c05e0db3eaf781fb21?s=128

Reeze Xia

February 03, 2015
Tweet

Transcript

  1. HHVM A High Performance PHP Engine 夏绪宏 reeze@php.net 商派电商技术沙⻰龙 ·

    PHP⾼高级架构技术
  2. About Me • 夏绪宏: 百度贴吧 • Weibo: @reeze • Website:

    http://reeze.cn/ • Github: http://github.com/reeze • Hiring: http://lamp.baidu.com/join-us/
  3. PHP Sucks!!

  4. Sorry! Just kidding ;-)

  5. PHP is the best language in the world! Surely,

  6. What I am going to talk about • I am

    NOT trying to convince you • PHP is a bad language, definitely not! • PHP is a good language, it…. just a prog language. • to use HHVM, try it yourself :) • Talk about HHVM & programming languages.
  7. Outline • Introduction • Architecture • What Makes HHVM Fast?

    • HHVM Goodies
  8. So, What is PHP? • The PHP Programming Language you

    ❤️ [1] • php.net (Zend PHP) is a reference implementation of PHP • Blah blah….. [1] https://github.com/php/php-langspec
  9. What is HHVM? • HHVM is another PHP implementation [1]

    • Start from a source code transformer: HPHPc • A Virtual Machine with a JIT Compiler • Support all PHP syntax • 97.16% open source project compatibility [2] [1] https://github.com/facebook/hhvm [2] http://hhvm.com/frameworks/
  10. What is HHVM? • Design goals of HHVM: • Compatibility

    • High Performance • Predictable Performance • Developer Productivity
  11. What is HHVM?

  12. Why • Why yet another PHP implementation? • PHP is

    SLOW, (back then) • No breaking improvements made
  13. Interpreter vs Compiler [1] • Interpreter: • one high level

    instruction (opcode) a time • execute source code by handlers • Compiler: • generate source code target low level code • execute low level code (eg: native code, ASM) [1] https://www.youtube.com/watch?v=_C5AHaS1mOA
  14. Different Implementations • HHVM • HippyVM • HappyJIT • etc…

    • PHP is a very large language, • Bug? Feature? Bug-Oriented-Programming :-)
  15. Who use it? [1] • Facebook • Baidu • Wikimedia

    • Box • etc… • Nonofficial source: Jd, Dangdang, Xiaomi etc… [1] https://github.com/facebook/hhvm/wiki/Users
  16. HHVM Architecture Overview

  17. HHVM Architecture

  18. HHVM Architecture HHVM – Process Model

  19. What Makes HHVM Fast? Backend Optimizations JIT Compiler Type Inference

    etc…
  20. HHVM – Compiling to Native Credit:Include Hack

  21. None
  22. Type Inference

  23. Example

  24. Interpreter:

  25. JIT • JIT: Just-In-Time Compiler • Runtime compilation • Compile

    to native machine code • Can take advantage of runtime information • Type information is crucial in dynamic typed language • Eliminate box/unbox cost • Eliminate type checking cost
  26. Tracelet is a: Single entry, (maybe) multiple exit region

  27. JIT

  28. JIT max2(1, 2)

  29. JIT

  30. Credit:Include Hack

  31. Credit:Include Hack

  32. HHVM Goodies

  33. Friendly Extension API • HNI: HHVM Native Interface

  34. Friendly Extension API • Systemlib: Write extension with PHP (JIT

    could help to improve perf)
  35. Hack Lang • Statically Typed • Async Functions • Generics

    • Return Typehints (Now PHP7 support it) • etc…
  36. Credit:Include Hack

  37. Admin Server • A friendly HTTP port • /stop •

    /check-health • /status • /vm-tcspace • /jemalloc-stats • etc… Page Server Admin Server Internal status booking & management Request Handling
  38. Conclusion

  39. HHVM drive the PHP community forward Performance New Features Standard

    Spec
  40. HHVM • HHVM is good at CPU bound apps: 50%

    reduction in really world apps • Hack’s async functions may help you improve performance as well • Compiles slowly & not support all of *Nix systems • Do your benchmarking, always.
  41. References • http://lamp.baidu.com • http://lamp.baidu.com/slides/introduction-to-hhvm/ • http://hhvm.com • http://wuduoyi.com/note/hhvm/ •

    《Include Hack》 • 《The HipHop Virtual Machine》
  42. Thank You!