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

JIT: So what?

JIT: So what?

Ricardo Coelho

December 05, 2020
Tweet

More Decks by Ricardo Coelho

Other Decks in Programming

Transcript

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

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

    $a; return $x; } echo f(“test”); Optimizations echo “test”;
  3. So, you’re telling me that after upgrading to PHP 7

    your code is running a lot faster? Congratulations, your code sucks!
  4. JIT

  5. 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
  6. @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…
  7. @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…
  8. @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…
  9. 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 ❤
  10. • 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…
  11. • 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