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.
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.
Easy::jit is a library that brings just-in-time compilation to C++ codes to achieve that goal.
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.
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.
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.
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.
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.
“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.”
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 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
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).
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With