Upgrade to Pro — share decks privately, control downloads, hide ads and more …

HHVM: A High Performance PHP Engine

Reeze Xia
February 03, 2015

HHVM: A High Performance PHP Engine

Reeze Xia

February 03, 2015
Tweet

More Decks by Reeze Xia

Other Decks in Programming

Transcript

  1. About Me • 夏绪宏: 百度贴吧 • Weibo: @reeze • Website:

    http://reeze.cn/ • Github: http://github.com/reeze • Hiring: http://lamp.baidu.com/join-us/
  2. 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.
  3. 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
  4. 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/
  5. What is HHVM? • Design goals of HHVM: • Compatibility

    • High Performance • Predictable Performance • Developer Productivity
  6. Why • Why yet another PHP implementation? • PHP is

    SLOW, (back then) • No breaking improvements made
  7. 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
  8. Different Implementations • HHVM • HippyVM • HappyJIT • etc…

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

    • Box • etc… • Nonofficial source: Jd, Dangdang, Xiaomi etc… [1] https://github.com/facebook/hhvm/wiki/Users
  10. 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
  11. JIT

  12. JIT

  13. Hack Lang • Statically Typed • Async Functions • Generics

    • Return Typehints (Now PHP7 support it) • etc…
  14. 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
  15. 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.