Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is PHP8 JIT compiler

Tags:

php

php-8

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.

like image 990
San Avatar asked Mar 07 '20 18:03

San


People also ask

What is JIT compiler explain?

The Just-In-Time (JIT) compiler is a component of the runtime environment that improves the performance of Java™ applications by compiling bytecodes to native machine code at run time.

Is C++ JIT compiled?

Easy::jit is a library that brings just-in-time compilation to C++ codes to achieve that goal.

What is JIT compiler and its types?

NET there are three types of JIT (Just-In-Time) compilers which are Explained as Under, Pre-JIT Compiler (Compiles entire code into native code completely) Econo JIT Compiler (Compiles code part by part freeing when required) Normal JIT Compiler (Compiles only that part of code when called and places in cache.

How does PHP JIT work?

JIT can bring performance improvements by compiling and storing the full or frequently called parts of a PHP application as CPU machine code, and directly execute it, which bypasses the Zend VM and its process overhead. JIT is a hybrid of the traditional interpreters and Ahead-Of-Time (AOT) compilers.

Does the JIT compiler in PHP 8 improve performance?

The JIT compiler, as present in PHP 8, doesn’t solve performance problems for a large set of applications. However, it does open new doors for PHP as a language — especially when applied to data heavy disciplines like machine learning. For additional information on the JIT compiler in PHP 8, be sure to check out my recent webinar below.

What is JIT (Just-in-time) in PHP 8?

Save this article as a PDF. Tired of scrolling? Download a PDF version for easier offline reading and sharing with coworkers. Are you ready? Let’s dive in! The most acclaimed feature coming with PHP 8 is the Just-in-time (JIT) compiler. What is JIT all about? “PHP JIT is implemented as an almost independent part of OPcache.

Is it possible to debug PHP JIT compiler with machine code?

For example: having machine code as output, it will be harder to debug possible bugs in PHP's JIT compiler. Luckily there are tools to help debugging.

How is PHP JIT implemented in Opcache?

“PHP JIT is implemented as an almost independent part of OPcache. It may be enabled/disabled at PHP compile time and at run-time. When enabled, native code of PHP files is stored in an additional region of the OPcache shared memory and op_array→opcodes [].handler (s) keep pointers to the entry points of JIT-ed code.”


2 Answers

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:

  • nikic/PHP-Parser ran about 1.3 times faster in benchmark made by Nikita Popov
  • A hello world application written with Amp had about 5% speed improvement
  • MessagePack benchmarks showed 1.3 to 1.5 times speed up

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).

like image 100
Jsowa Avatar answered Oct 16 '22 15:10

Jsowa


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.

like image 1
Rain Avatar answered Oct 16 '22 16:10

Rain