$30 off During Our Annual Pro Sale. View Details »

JIT: So what?

JIT: So what?

Ricardo Coelho

December 05, 2020
Tweet

More Decks by Ricardo Coelho

Other Decks in Programming

Transcript

  1. Ricardo Coelho – @ramcoelho
    JIT
    So what?

    View Slide

  2. View Slide

  3. JIT
    So what?

    View Slide

  4. 5 ➞ 7

    View Slide

  5. opcache

    View Slide

  6. opcache
    CPU

    View Slide

  7. opcache
    ARM
    MIPS
    X86

    View Slide

  8. Optimizations
    Escape Analysis

    View Slide

  9. $newVariable = ‘undefined’;
    if ($isTrue) {
    $newVarible = ‘true’;
    } else {
    $newVariable = ‘false’;
    }
    Optimizations (DCE)
    $newVariable = ‘false’;
    if ($isTrue) {
    $newVarible = ‘true’;
    }

    View Slide

  10. function f($x) {
    $a = 15;
    $b = 5 * $a;
    return $x;
    }
    echo f(“test”);
    Optimizations
    echo “test”;

    View Slide

  11. 5 ➞ 7

    View Slide

  12. 200% Drupal
    300% Magento
    400% Wordpress
    5 ➞ 7
    source: www.zend.com/blog/php-7

    View Slide

  13. 01 02
    03 ;

    View Slide

  14. So, you’re telling me
    that after upgrading to
    PHP 7 your code is
    running a lot faster?
    Congratulations,
    your code sucks!

    View Slide

  15. 7 ➞ 8

    View Slide

  16. JIT

    View Slide

  17. ust n ime
    J I T

    View Slide

  18. https://youtu.be/dWH65pmnsrI

    View Slide

  19. 01 02
    03 echo “Hello World!”;
    0000000 cf fa ed fe 07 00 00 01 03 00 00 00 02 00 00 00
    0000010 10 00 00 00 58 05 00 00 85 00 20 00 00 00 00 00
    0000020 19 00 00 00 48 00 00 00 5f 5f 50 41 47 45 5a 45
    0000030 52 4f 00 00 00 00 00 00 00 00 00 00 00 00 00 00
    (…)
    000c0f0 5f 73 74 75 62 5f 62 69 6e 64 65 72 00 5f 5f 64
    000c100 79 6c 64 5f 70 72 69 76 61 74 65 00 00 00 00 00

    View Slide

  20. Interpreted
    vs.
    Compiled

    View Slide

  21. Monitor / Profiler

    View Slide

  22. Warm code

    View Slide

  23. Hot code optimization

    View Slide

  24. opcache
    ARM
    MIPS
    X86

    View Slide

  25. opcache
    ARM
    MIPS
    X86
    jit

    View Slide

  26. docker run --rm php:8.0.0-cli php -v
    Let’s test it…

    View Slide

  27. docker run --rm -it php:8.0.0-cli bash
    Let’s test it…

    View Slide

  28. @host$ docker run --rm -it php:8.0.0-cli bash
    @php8$ echo “@php8$ docker-php-ext-enable opcache
    @php8$ echo “Let’s test it…

    View Slide

  29. @host$ wget https://bit.ly/jit-so-what
    @host$ unzip jit-so-what
    @host$ cd jit-so-what—1.0
    @host$ docker run --rm -it -p 80:80
    -v $(pwd)/php.ini:/usr/local/etc/php/php.ini
    -v $(pwd):/app
    php:8.0.0-cli bash
    Let’s test it…

    View Slide

  30. @php8$ php /app/run.php
    @php8$ php -S 0.0.0.0:80 -t /app
    @host$ ab -n 40 -c 20 -l http://localhost/run.php
    @php8$ docker-php-ext-enable opcache
    @host$ ab -n 40 -c 20 -l http://localhost/run.php
    Let’s test it…

    View Slide

  31. Results
    Concurrency Level: 20
    Time taken for tests: 77.639 seconds
    Complete requests: 40
    Failed requests: 0
    Total transferred: 252800 bytes
    HTML transferred: 246520 bytes
    Requests per second: 0.52 [#/sec] (mean)
    Time per request: 38819.662 [ms]
    (mean)
    Time per request: 1940.983 [ms]
    (mean, across all concurrent requests)
    Transfer rate: 3.18 [Kbytes/sec]
    received
    Concurrency Level: 20
    Time taken for tests: 7.673 seconds
    Complete requests: 40
    Failed requests: 0
    Total transferred: 252800 bytes
    HTML transferred: 246520 bytes
    Requests per second: 5.21 [#/sec] (mean)
    Time per request: 3836.614 [ms]
    (mean)
    Time per request: 191.831 [ms]
    (mean, across all concurrent requests)
    Transfer rate: 32.17 [Kbytes/sec]
    received
    JIT

    View Slide

  32. source: www.php.net/releases/8.0/en.php

    View Slide

  33. Types, DOM and
    frustrated expectations
    (failed guard)

    View Slide

  34. Deoptimization
    (bailout)

    View Slide

  35. I/O bound?
    Little to no reuse?
    Short lifespan execution?
    ➞ i.e. Web Applications

    View Slide

  36. 5-20 %

    View Slide

  37. Is it worth the trouble?

    View Slide

  38. • extension developers who would prefer to write it in PHP,
    instead of C;

    • CPU intensive code;

    • strongly typed variables and well-defined and stable data
    structures;

    • squeezing the last drop of performance.
    It is worth for…

    View Slide

  39. Questions?
    Thank You!

    View Slide

  40. • https://wiki.php.net/rfc/jit

    • https://stitcher.io/blog/new-in-php-8

    • https://stitcher.io/blog/php-jit

    • https://stitcher.io/blog/jit-in-real-life-web-applications

    • https://kinsta.com/pt/blog/php-8/

    • https://hacks.mozilla.org/2017/02/a-crash-course-in-just-in-time-jit-compilers/

    • https://github.com/mente/php-docker-jit

    • https://mobile.twitter.com/dr4goonis/status/806817526097346560

    References

    View Slide