What to look out for testing PHP8 JIT

PHP 8 is coming with a Just In Time Compiler (JIT) and people are starting to test it in more detail. Here are a few things you should be careful about when testing the JIT:

  • Make sure sure test with different trigger modes. Trigger is the 3rd number in the line: 1205 (JIT everything), 1235 (JIT hot code based on relative usage), 1255 (trace hot code for JITability).

    Best results seem to be with "opcache.jit=1255" at the moment.

  • Do not run your examples in the CLI. Use "php-cgi" with the -T flag for reptitions. This allows Opcache and JIT to optimize on the first request, and then you can see in the following repetitions how the optimized performance is. Just for experimenting it makes sense to have "php-cgi -T 2" for running one warmup and one hot request against the same script.

    Clarification: JIT works with the CLI, but I find its harder to make the exact effects visible and comparable and requires more configuration.

  • Make sure the JIT is actually running by looking at opcache_get_status(false). It has a key "jit" and it should have a key "on" set to true, and the "buffer_free" should be lower than "buffer_size", meaning the JIT actually uses some of the allocated memory for something.
  • To test if code gets faster with JIT, don't run it under stress/concurrency. JIT optimizes CPU time, so the improvement must already be visible when running one jitted request against one unjitted one. Repeat those runs multiple times to find out if the result is "stable" or fluctuates a lot.
  • If you want to test if JIT increases throughput, that means more requests can be handled at the same time than without JIT, then you should ramp-up the number of concurrent requests and not start with a high number. Start with 10, and go up to 100, 1000, ... - At some point "regular" PHP will fall over and you can then find how much more JIT takes before it also falls over.

Testing JIT performance for Doctrine ORM I setup this Github repository with more detailed examples, especially the php-cgi call, which I want to repeat here:

/opt/php/php-src/bin/php-cgi -T 10 -dopcache.enable=1 -dopcache.jit=1255 -dopcache.jit_buffer_size=64M index.php

The -T 10 here means 10 reptitions of the index.php script. This triggers OPCache and JIT optimizations on the first request and allows testing performance of already optimized code in subsequent requests.

The ini settings explained:

  • opcache.enable=1 enables OPCache.
  • opcache.jit=1255 sets various flags, including the triggering mode, of the JIT. Defaults to 1205, which is probably inefficient JITing everything.
  • opcache.jit_buffer_size=64M must be set, because otherwise JIT is not enabled. By default this is zero. At the moment setting the buffer size is the switch to enable/disable JIT. It is planned to change INI settings slightly before the PHP 8.0 GA to simplify this step.

Looking forward to read more about the JIT experience from all of you!


  • July 5th, clarified JIT works with CLI, added detailed explanation about JIT INI settings
Published: 2020-07-05