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

JIT: So what?

JIT: So what?

B82b1da7a58dcf37c8f0461c5c08ec0a?s=128

Ricardo Coelho

December 05, 2020
Tweet

Transcript

  1. Ricardo Coelho – @ramcoelho JIT So what?

  2. None
  3. JIT So what?

  4. 5 ➞ 7

  5. opcache

  6. opcache CPU

  7. opcache ARM MIPS X86

  8. Optimizations Escape Analysis

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

    else { $newVariable = ‘false’; } Optimizations (DCE) $newVariable = ‘false’; if ($isTrue) { $newVarible = ‘true’; }
  10. function f($x) { $a = 15; $b = 5 *

    $a; return $x; } echo f(“test”); Optimizations echo “test”;
  11. 5 ➞ 7

  12. 200% Drupal 300% Magento 400% Wordpress 5 ➞ 7 source:

    www.zend.com/blog/php-7
  13. 01 <?php 02 03 ;

  14. So, you’re telling me that after upgrading to PHP 7

    your code is running a lot faster? Congratulations, your code sucks!
  15. 7 ➞ 8

  16. JIT

  17. ust n ime J I T

  18. https://youtu.be/dWH65pmnsrI

  19. 01 <?php 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
  20. Interpreted vs. Compiled

  21. Monitor / Profiler

  22. Warm code

  23. Hot code optimization

  24. opcache ARM MIPS X86

  25. opcache ARM MIPS X86 jit

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

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

  28. @host$ docker run --rm -it php:8.0.0-cli bash @php8$ echo “<?php

    opcache_get_status();”|php ❌ @php8$ docker-php-ext-enable opcache @php8$ echo “<?php opcache_get_status();”|php ✅ Let’s test it…
  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…
  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…
  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 ❤
  32. source: www.php.net/releases/8.0/en.php

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

  34. Deoptimization (bailout)

  35. I/O bound? Little to no reuse? Short lifespan execution? ➞

    i.e. Web Applications
  36. 5-20 %

  37. Is it worth the trouble?

  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…
  39. Questions? Thank You!

  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