Site icon David Yin's Blog

Enable JIT on PHP8.2.6

Enable Just-In-Time(JIT) compilation is very important for PHP performance. So I will enable it on PHP 8.2.6. I have a post discussing it with PHP 8.0 in 2021. Now It is 2023, on PHP 8.2.x. It is different.

Last post when I did the performance tests on PHP 8.2.6, the JIT is not enabled.

Test Result on PHP8.2.6 with JIT enabled.

When I enabled the JIT on PHP 8.2.6 on the same machine. The test result is below.

The Bench Test Result

simple             0.001
simplecall         0.000
simpleucall        0.000
simpleudcall       0.000
mandel             0.005
mandel2            0.006
ackermann(7)       0.005
ary(50000)         0.002
ary2(50000)        0.001
ary3(2000)         0.005
fibo(30)           0.013
hash1(50000)       0.004
hash2(500)         0.003
heapsort(20000)    0.005
matrix(20)         0.003
nestedloop(12)     0.003
sieve(30)          0.002
strcat(200000)     0.002
------------------------
Total              0.061

 

The Micro-Bench Test Result

empty_loop         0.001
func()             0.001    0.000
undef_func()       0.001    0.000
int_func()         0.001    0.000
$x = self::$x      0.059    0.057
self::$x = 0       0.053    0.051
isset(self::$x)    0.047    0.046
empty(self::$x)    0.051    0.049
$x = Foo::$x       0.027    0.025
Foo::$x = 0        0.018    0.016
isset(Foo::$x)     0.020    0.018
empty(Foo::$x)     0.022    0.021
self::f()          0.001    0.000
Foo::f()           0.001    0.000
$x = $this->x      0.008    0.006
$this->x = 0       0.011    0.009
$this->x += 2      0.007    0.005
++$this->x         0.006    0.005
--$this->x         0.006    0.005
$this->x++         0.006    0.005
$this->x--         0.006    0.005
isset($this->x)    0.028    0.026
empty($this->x)    0.030    0.028
$this->f()         0.019    0.018
$x = Foo::TEST     0.029    0.027
new Foo()          0.106    0.105
$x = TEST          0.007    0.005
$x = $_GET         0.031    0.030
$x = $GLOBALS['v'] 0.027    0.026
$x = $hash['v']    0.001    0.000
$x = $str[0]       0.001    0.000
$x = $a ?: null    0.001    0.000
$x = $f ?: tmp     0.001    0.000
$x = $f ? $f : $a  0.001    0.000
$x = $f ? $f : tmp 0.001    0.000
------------------------
Total              0.640

 

The Bubble Test Result

0.022209882736206

Performance comparison

Compared them with the performance without JIT enabled. It is about 63% improvement on the Bench test script, about 41% improvement on the Micro-Bench test script, and about 45% improvement on the Bubble test script.

On average, about 50% performance improvement with JIT enabled.

How to enable JIT on PHP 8.2.6, Ubuntu 22.04LTS.

  1. SSH to the server, edit the file /etc/php/8.2/mods-available/opcache.ini
  2. find the place to add following into the file and save it.

// /etc/php/8.2/mods-available/opcache.ini

opcache.jit=1255

opcache.jit_buffer_size=100M

Then restart the php8.2-fpm service with the command sudo service php8.2-fpm restart

Check the phpinfo() again.

 

 

OK, now the JIT is enabled and working.

Another thing I want to talk about.

Let me discuss a little bit about the values of the opcache.jit.

Here is a blog post from droptica.com which is discuss more details about PHP 8 with the JIT compiler.

I am just wondering why the default value of this JIT configuration is disabled. Is it always good to enable it for better PHP script performance?

Exit mobile version