PHP-8.4/9 to Introduce New JIT Engine for Improved Performance
PHP, one of the world’s most popular web programming languages, is set to take a major leap forward with the introduction of a new Just-In-Time (JIT) engine in its upcoming major release, PHP-8.4/9. This innovation promises to deliver enhanced performance and wider optimization possibilities.
Since the current compiler is difficult to modify, this change lays the groundwork for future improvements and abstracts many of the low-level details that were present in the previous version of PHP’s JIT.
In this article, we will explore in detail the pros and cons of this significant engine update, PHP’s JIT.
Comparison with PHP 8.* JIT Approach – The New Paradigm
Just-in-Time (JIT) is a technique used in computer language compilation. It helps improve performance by compiling certain parts of the source code at runtime.
Unlike the previous approach in PHP 8.*, which generated native code directly from PHP bytecode, the PHP-8.4/9 version introduces a revolutionary approach based on Intermediate Representation (IR) – a lightweight JIT compilation framework.
With the current approach, PHP 8.* JIT only compiles certain parts of the source code at runtime. This helps improve performance but is limited in terms of overall optimization. On the other hand, the new JIT based on the IR framework offers a more advanced approach by compiling the entire source code into an intermediate representation. This representation then allows for more optimizations to be applied before execution.
Key Benefits of the New JIT Compilation
First and foremost, thanks to this new approach, it is possible to further enhance the performance of applications developed with PHP. In fact, the complete compilation of the source code allows for global optimization that can lead to much faster executions.
- The use of IR opens the door to greater optimization and more efficient register allocation, resulting in higher performance of native code.
- This new approach frees PHP from low-level details such as different processor architectures, calling conventions, TLS details, etc.
- It also makes it much easier to support new targets, such as the RISCV architecture.
Another notable advantage is the separation of the IR framework from PHP’s own development. This means that the IR framework can accept contributions from other projects, whether it be for new optimizations, improvements, or bug fixes. (IR: Lightweight JIT Compilation Framework)
The new JIT engine based on the IR framework is a significant advancement that promises to greatly improve the performance and possibilities offered by PHP.
Drawbacks and Impacts to Note
However, it is important to note that this new JIT compilation method can cause a slowdown in the compilation process. Although this is almost imperceptible for JIT tracing, JIT compilation of WordPress can be up to 4 times slower.
Another point to consider is that the IR framework is integrated into PHP as a secondary GIT module. To obtain it, you must use the following command:
It is also worth noting that, although this new JIT implementation has successfully completed all CI workflows, including nightly, it is still not considered fully mature and may potentially cause failures.
Smooth Transition and Maintenance of Previous Implementation in PHP 8.3
Despite the introduction of the new JIT implementation based on the IR framework for PHP, the development team has not completely removed the previous implementation present in PHP 8.3.
In order to reduce risks associated with this major update, the patch does not remove the old JIT implementation, which is identical to that of PHP-8.3. Thus, it is still possible to build PHP with the old JIT by configuring it with the option –disable-opcache-jit-ir.
By maintaining the previous implementation, the developers also took into account that some projects may not be compatible with the new approach or may require additional adjustments before migrating them.
However, it is important to note that although it is maintained in PHP 8.3, the old JIT implementation will no longer benefit from the updates and improvements made in the new IR framework-based model. In the future, there are plans to completely remove the previous implementation.
Future Integration of the IR Framework into the php-src Repository
Work is currently underway to integrate the IR framework into the php-src repository. This integration aims to make this new Just-In-Time approach more seamless.
In fact, the git submodules have a terrible user experience and relying on Dmitry Stogov’s personal GitHub account repository is problematic.
This will also facilitate the integration of these changes into future PHP versions,