6

What is PHP8 JIT? and what are the advantages it can bring to the PHP world? What I understand is, it is used for the performance improvement.

Jsowa
  • 4,188
  • 4
  • 23
  • 35
San
  • 628
  • 7
  • 23

2 Answers2

6

JIT (Just in Time) compiler in PHP works the same as in the other interpreted programming language. It runs after the program starts and compiles code on the fly (at the runtime).

In PHP8 JIT will omit Zend VM and if the compiled code is already cached it is sent directly to the CPU. It will not depend on C language and the language will get ability to develop its own new features.

JIT scheme https://thephp.website/en/issue/php-8-jit/

JIT in PHP8 is not a game changer in performance. It will improve it slightly, but not as significantly as PHP7 did. There are already some benchmarks showing that the performance in basic benchmarks (CPU intensive tasks) is much better, but in real-use applications it doesn't change much.

Article about JIT performance

CPU intensive tasks:

Results of fresh laravel webpage:

  • PHP 7.3: 131.37 req/s
  • PHP 8.0 + JIT: 133.57 req/s

Relative JIT contribution to PHP 8 performance source PHP 8 performance https://www.php.net/images/php8/scheme.svg

Nice article with pros and cons for JIT.

  • It opens the door for PHP to be used as a very performant language outside of the web.
  • The JIT can be improved upon over time, as well could our code.

If PHP code can be interpreted in the runtime avoiding VM it means more opportunities in the future for PHP itself for CPU-intensive tasks like Machine learning.

There are several types of configuration for JIT in PHP. You can set optimization level, trigger, register allocation and CPU specific optimization flag. I will not paste everything, but it may be found in the documentation (there is no official JIT documentation yet, only RFC).

Jsowa
  • 4,188
  • 4
  • 23
  • 35
1

Now that the first alpha has been released I would say benchmarks are very promising.

A reduction in time of approximately 50% compared to PHP 7

PHP8 JIT excels in non-trivial tasks especially mathematical tasks and it's also promising for non-blocking (Asynchronous) applications. However, JIT will not make PHP C language all of a sudden, code still need to be highly optimised somehow to see the real power of JIT.

See this Mandelbrot example (Proof-of-Concept) by Zeev Suraski to see how powerful JIT in PHP 8 is.

Rain
  • 1,745
  • 1
  • 11
  • 23