PHP 8 vs PHP 7.4, PHP7.3 Performance

Let’s test PHP 8 performance with a JIT.

PHP 8.0 Performance vs PHP 7.x

Even if opcodes are in the form of low-level intermediate representation, they still have to be compiled into machine code. JIT “doesn’t introduce any additional IR (Intermediate Representation) form”, but uses DynASM (Dynamic Assembler for code generation engines) to generate native code directly from PHP byte-code.

In short, JIT translates the hot parts of the intermediate code into machine code. Bypassing compilation, it’d be able to bring considerable improvements in performance and memory usage.

for the test, we will use the docker image: https://hub.docker.com/r/phpdockerio/php80-fpm

Settings in PHP.ini

; Enables or disables JIT compilation of patterns. This requires the PCRE
; library to be compiled with JIT support.
pcre.jit=1

Opcache parameters to:

opcache.jit=1
opcache.enable_cli=1

For this test, we are using C5.large AWS instance.

PHP 8.0 test performance

Running our test script:

The code took 0.073684930801392 seconds to complete.
The code took 0.074541091918945 seconds to complete.
The code took 0.073902130126953 seconds to complete.
The code took 0.074251890182495 seconds to complete.
The code took 0.07374095916748 seconds to complete.
The code took 0.073745012283325 seconds to complete.
The code took 0.073945045471191 seconds to complete.
The code took 0.073848962783813 seconds to complete.
The code took 0.074243068695068 seconds to complete.
The code took 0.073872089385986 seconds to complete.
The code took 0.073964834213257 seconds to complete.

Tring to run on the local server.

The code took 0.074733018875122 seconds to complete. root@d5a21c0335c4:/# curl localhost:8000/test.php
The code took 0.074043989181519 seconds to complete. root@d5a21c0335c4:/# curl localhost:8000/test.php
The code took 0.074050903320312 seconds to complete. root@d5a21c0335c4:/# curl localhost:8000/test.php
The code took 0.073812007904053 seconds to complete. root@d5a21c0335c4:/# curl localhost:8000/test.php
The code took 0.073884010314941 seconds to complete. root@d5a21c0335c4:/# curl localhost:8000/test.php
The code took 0.074115037918091 seconds to complete. root@d5a21c0335c4:/# curl localhost:8000/test.php
The code took 0.073699951171875 seconds to complete. root@d5a21c0335c4:/# curl localhost:8000/test.php
The code took 0.073861837387085 seconds to complete. root@d5a21c0335c4:/# curl localhost:8000/test.php
The code took 0.074131965637207 seconds to complete. root@d5a21c0335c4:/# curl localhost:8000/test.php
The code took 0.074096202850342 seconds to complete. root@d5a21c0335c4:/# curl localhost:8000/test.php
The code took 0.073999166488647 seconds to complete. root@d5a21c0335c4:/# curl localhost:8000/test.php
The code took 0.074022054672241 seconds to complete.

Test PHP 7.4

root@ea0a1a583ed8:/var/www/html# php -v
PHP 7.4.12 (cli) (built: Nov 18 2020 09:41:41) ( NTS )
Copyright (c) The PHP Group
Zend Engine v3.4.0, Copyright (c) Zend Technologies
root@ea0a1a583ed8:/var/www/html# php test.php
The code took 0.099517107009888 seconds to complete.
root@ea0a1a583ed8:/var/www/html# php test.php
The code took 0.10780692100525 seconds to complete.
root@ea0a1a583ed8:/var/www/html# php test.php
The code took 0.09947395324707 seconds to complete.
root@ea0a1a583ed8:/var/www/html# php test.php
The code took 0.099421977996826 seconds to complete.
root@ea0a1a583ed8:/var/www/html# php test.php
The code took 0.10767197608948 seconds to complete.
root@ea0a1a583ed8:/var/www/html# php test.php
The code took 0.10780000686646 seconds to complete.
root@ea0a1a583ed8:/var/www/html# php test.php
The code took 0.099364995956421 seconds to complete.
root@ea0a1a583ed8:/var/www/html# php test.php
The code took 0.099454879760742 seconds to complete.
root@ea0a1a583ed8:/var/www/html# php test.php
The code took 0.10798311233521 seconds to complete.
root@ea0a1a583ed8:/var/www/html# php test.php
The code took 0.10803985595703 seconds to complete.
root@ea0a1a583ed8:/var/www/html# php test.php
The code took 0.099156856536865 seconds to complete.
root@ea0a1a583ed8:/var/www/html# php test.php
The code took 0.099501848220825 seconds to complete.
root@ea0a1a583ed8:/var/www/html# php test.php
The code took 0.099478006362915 seconds to complete.

Test PHP 7.3

[ec2-user@ip ~]$ php -v
PHP 7.3.21 (cli) (built: Aug 21 2020 21:12:16) ( NTS )
Copyright (c) 1997-2018 The PHP Group
Zend Engine v3.3.21, Copyright (c) 1998-2018 Zend Technologies
with Zend OPcache v7.3.21, Copyright (c) 1999-2018, by Zend Technologies
[ec2-user@ip ~]$ php test.php
The code took 0.10289692878723 seconds to complete.
[ec2-user@ip ~]$ php test.php
The code took 0.10567092895508 seconds to complete.
[ec2-user@ip ~]$ php test.php
The code took 0.10027503967285 seconds to complete.
[ec2-user@ip ~]$ php test.php
The code took 0.10293197631836 seconds to complete.
[ec2-user@ip ~]$ php test.php
The code took 0.1053740978241 seconds to complete.
[ec2-user@ip ~]$ php test.php
The code took 0.10305786132812 seconds to complete.
[ec2-user@ip ~]$ php test.php
The code took 0.102942943573 seconds to complete.
[ec2-user@ip ~]$ php test.php

I don’t know where is there PHP 8.0 JIT compilation however PHP 8.0 is almost 30% faster than PHP 7.4.

If somebody knows how to test the PHP JIT compilation, please, leave a comment.

Magento/APP Cloud Architect. Melting metal server infrastructure into cloud solutions.