PHP 7.3 will have improved performance

What's new in PHP 7.3

The latest PHP 7.3 has introduced several core changes and deprecation of functionalities. One of the most important change is that the cyclic Garbage Collector has been enhanced. This may result in considerable performance improvements for your average PHP site.

GC Improvement

I did some testing with a quickly done horrible Laravel project that does very stupid things. I ran their tests on a Virtual Machine I spinned up with 32 cores and 64 GB of RAM. Although RAM is abundant nowadays, read/write speed of RAM has not improved significantly. Hence, these results might not differ from a modern laptop you are running. Results – there are some slight difference between PHP 7.2 and 7.3.

So here are the tabulated results.

Test CasePHP 7.2PHP 7.3
Repetitive Math Sum #140.59031987190239.114274024963
Repetitive Math Sum #140.38330197334338.955203056335
Repetitive Math Sum #140.43135499954238.510466814041
Repetitive Math Sum #140.55468797683738.414289951324
Repetitive Math Sum #140.32460999488839.437994003296
Repetitive Math Sum #140.30958390235938.586963891983
Repetitive Math Sum #140.49155712127738.527884960175
Repetitive Math Sum #140.56119108200138.572283983231
Repetitive Math Sum #140.39918398857138.274201154709
Repetitive Math Sum #140.37809491157539.014632940292
Repetitive Math Sum #240.48223686218339.098721981049
Repetitive Math Sum #240.38750600814838.896921873093
Repetitive Math Sum #240.26209592819238.51801609993
Repetitive Math Sum #240.4820611476938.506614923477
Repetitive Math Sum #240.33934998512338.705502033234
Repetitive Math Sum #240.30415987968438.672913074493
Repetitive Math Sum #240.32841110229538.605751991272
Repetitive Math Sum #240.33660292625438.660679101944
Repetitive Math Sum #240.44733214378438.278237819672
Repetitive Math Sum #240.39918017387438.887251138687
Repetitive Object Creation & Removal #147.22138690948542.577863931656
Repetitive Object Creation & Removal #146.49003195762643.560690164566
Repetitive Object Creation & Removal #147.30391979217542.877938985825
Repetitive Object Creation & Removal #147.84495997428942.660858869553
Repetitive Object Creation & Removal #147.97174000740143.204864025116
Repetitive Object Creation & Removal #147.392125129742.887193202972
Repetitive Object Creation & Removal #146.79433894157443.227856874466
Repetitive Object Creation & Removal #147.04512381553643.104037046432
Repetitive Object Creation & Removal #147.63871502876342.578276157379
Repetitive Object Creation & Removal #147.70044183731142.945841789246
Repetitive Object Creation & Removal #271.102308988571Segmentation fault (core dumped)
Repetitive Object Creation & Removal #269.664057016373Segmentation fault (core dumped)
Repetitive Object Creation & Removal #270.938825845718Segmentation fault (core dumped)
Repetitive Object Creation & Removal #271.190234899521Segmentation fault (core dumped)
Repetitive Object Creation & Removal #272.151322126389Segmentation fault (core dumped)
Repetitive Object Creation & Removal #271.034454107285Segmentation fault (core dumped)
Repetitive Object Creation & Removal #270.705224990845Segmentation fault (core dumped)
Repetitive Object Creation & Removal #270.763866901398Segmentation fault (core dumped)
Repetitive Object Creation & Removal #270.451802015305free(): invalid pointer
Repetitive Object Creation & Removal #270.846419095993Segmentation fault (core dumped)

The raw results are appended at the bottom of the post.

The results we want to take a look at for GC improvement is ‘Repetitive Object Creation & Removal #1’ and ‘Repetitive Object Creation & Removal #2’. The difference between these 2 is that #2 attempts to a manual GC cycle after an ‘unset’ is called. An interesting observation is that PHP 7.3 refuses to handle the terrible circular object references I’ve implanted.

Other than that, we can observe that there’s a slight improvement in execution for #1. Its an average of 47 seconds VS 42 seconds – a five seconds improvement which might translate to an observable slight difference for a typical site that heavily uses classes and objects.

These sites include but are not limited to sites that relies heavily on frameworks, especially those that implement Active Record pattern. WordPress sites might not have much improvements.

Code Optimization

There has been some improvements made to the Zend code optimizer as well. These changes are able to catch some rare cases and optimize them as the previous version would not have. Your code needs to be very bad and had edge cases which the former optimizer could not detect for the speed to improve.

As observed in the results printed above (Repetitive Math Sum #1 & Repetitive Math Sum #2), you’ll notice that there’s only consistent two seconds improvement between PHP 7.2 and PHP 7.3. Do note that the code execution took 40 seconds vs 38 seconds.

Other than that, if you take a look at online benchmarks, you will notice that there are some slight performance improvements. This might not be due to the enhanced GC but rather due to this code optimization improvement. For example, PHP 7.3 Laravel vs PHP 7.2 Laravel.

Mono-atomic timer

Support for mono-atomic timer as a function (hrtimer) has been added. This feature is particularly useful for creating time-sensitive software such as highly available databases which usually uses a mono-atomic clock (sometimes combined with GPS clock) for tuple timestamp. With this, we might even have a new highly available database software programmed in PHP!

A mono-atomic clock is not affected by seconds leap and will only tick forward according to its CPU ticks. Its relatively simple to measure the rough equivalent of 5 seconds in a mono-atomic timer. Usually, you might want to get an average as sleep is not very exact. 5 seconds might actually be 5.000002 seconds or 4.9964 seconds, etc.

<?php
$start = hrtime(true);
sleep(5);
$end = hrtime(true);
$five_seconds_in_mono_atomic = $end - $start;

Xdebug Incompatibility Issue

Apparently, PHP 7.3 is not compatible with Xdebug versions 2.6.x and requires the beta version 2.7.0beta1. More information about this can be seen on the xdebug bug issue.

Deprecation & Support For Enterprises

Support for ODBCRouter and Birdstep has been removed. These were very old unsupported stuff and was deprecated long ago. Overall, there hasn’t been too much of deprecation and incompatibility between PHP 7.2 and 7.3. This means that the upgrade process would be relatively easier as compared to when upgrading from 7.1 to 7.2.

PHP 7.3 will have active support until 6 Dec 2020 whilst security support until 6 Dec 2021. Active support meant that new minor features, improvements, bug fixes and security fixes will be provided. Security support meant that only security fixes will be provided.

All PHP support timeline is visible on the PHP site.

Raw Results

[[email protected] horrible-site]# php72 vendor/bin/phpunit
PHPUnit 7.5.1 by Sebastian Bergmann and contributors.

..40.590319871902.40.482236862183.47.221386909485.                                                               5 / 5 (100%)71.102308988571

Time: 3.32 minutes, Memory: 19688.00MB

OK (5 tests, 5 assertions)
[[email protected] horrible-site]# php72 vendor/bin/phpunit
PHPUnit 7.5.1 by Sebastian Bergmann and contributors.

..40.383301973343.40.387506008148.46.490031957626.                                                               5 / 5 (100%)69.664057016373

Time: 3.28 minutes, Memory: 19688.00MB

OK (5 tests, 5 assertions)
[[email protected] horrible-site]# php72 vendor/bin/phpunit
PHPUnit 7.5.1 by Sebastian Bergmann and contributors.

..40.431354999542.40.262095928192.47.303919792175.                                                               5 / 5 (100%)70.938825845718

Time: 3.31 minutes, Memory: 19688.00MB

OK (5 tests, 5 assertions)
[[email protected] horrible-site]# php72 vendor/bin/phpunit
PHPUnit 7.5.1 by Sebastian Bergmann and contributors.

..40.554687976837.40.48206114769.47.844959974289.                                                               5 / 5 (100%)71.190234899521

Time: 3.33 minutes, Memory: 19688.00MB

OK (5 tests, 5 assertions)
[[email protected] horrible-site]# php72 vendor/bin/phpunit
PHPUnit 7.5.1 by Sebastian Bergmann and contributors.

..40.324609994888.40.339349985123.47.971740007401.                                                               5 / 5 (100%)72.151322126389

Time: 3.34 minutes, Memory: 19688.00MB

OK (5 tests, 5 assertions)
[[email protected] horrible-site]# php72 vendor/bin/phpunit
PHPUnit 7.5.1 by Sebastian Bergmann and contributors.

..40.309583902359.40.304159879684.47.3921251297.                                                               5 / 5 (100%)71.034454107285

Time: 3.31 minutes, Memory: 19688.00MB

OK (5 tests, 5 assertions)
[[email protected] horrible-site]# php72 vendor/bin/phpunit
PHPUnit 7.5.1 by Sebastian Bergmann and contributors.

..40.491557121277.40.328411102295.46.794338941574.                                                               5 / 5 (100%)70.705224990845

Time: 3.3 minutes, Memory: 19688.00MB

OK (5 tests, 5 assertions)
[[email protected] horrible-site]# php72 vendor/bin/phpunit
PHPUnit 7.5.1 by Sebastian Bergmann and contributors.

..40.561191082001.40.336602926254.47.045123815536.                                                               5 / 5 (100%)70.763866901398

Time: 3.31 minutes, Memory: 19688.00MB

OK (5 tests, 5 assertions)
[[email protected] horrible-site]# php72 vendor/bin/phpunit
PHPUnit 7.5.1 by Sebastian Bergmann and contributors.

..40.399183988571.40.447332143784.47.638715028763.                                                               5 / 5 (100%)70.451802015305

Time: 3.31 minutes, Memory: 19688.00MB

OK (5 tests, 5 assertions)
[[email protected] horrible-site]# php72 vendor/bin/phpunit
PHPUnit 7.5.1 by Sebastian Bergmann and contributors.

..40.378094911575.40.399180173874.47.700441837311.                                                               5 / 5 (100%)70.846419095993

Time: 3.32 minutes, Memory: 19688.00MB

OK (5 tests, 5 assertions)

[[email protected] horrible-site]# php73 vendor/bin/phpunit
PHPUnit 7.5.1 by Sebastian Bergmann and contributors.

..39.114274024963.39.098721981049.42.577863931656Segmentation fault (core dumped)
[[email protected] horrible-site]# php73 vendor/bin/phpunit
PHPUnit 7.5.1 by Sebastian Bergmann and contributors.

..38.955203056335.38.896921873093.43.560690164566Segmentation fault (core dumped)
[[email protected] horrible-site]# php73 vendor/bin/phpunit
PHPUnit 7.5.1 by Sebastian Bergmann and contributors.

..38.510466814041.38.51801609993.42.877938985825Segmentation fault (core dumped)
[[email protected] horrible-site]# php73 vendor/bin/phpunit
PHPUnit 7.5.1 by Sebastian Bergmann and contributors.

..38.414289951324.38.506614923477.42.660858869553Segmentation fault (core dumped)
[[email protected] horrible-site]# php73 vendor/bin/phpunit
PHPUnit 7.5.1 by Sebastian Bergmann and contributors.

..39.437994003296.38.705502033234.43.204864025116Segmentation fault (core dumped)
[[email protected] horrible-site]# php73 vendor/bin/phpunit
PHPUnit 7.5.1 by Sebastian Bergmann and contributors.

..38.586963891983.38.672913074493.42.887193202972Segmentation fault (core dumped)
[[email protected] horrible-site]# php73 vendor/bin/phpunit
PHPUnit 7.5.1 by Sebastian Bergmann and contributors.

..38.527884960175.38.605751991272.43.227856874466Segmentation fault (core dumped)
[[email protected] horrible-site]# php73 vendor/bin/phpunit
PHPUnit 7.5.1 by Sebastian Bergmann and contributors.

..38.572283983231.38.660679101944.43.104037046432Segmentation fault (core dumped)
[[email protected] horrible-site]# php73 vendor/bin/phpunit
PHPUnit 7.5.1 by Sebastian Bergmann and contributors.

..38.274201154709.38.278237819672.42.578276157379free(): invalid pointer
Aborted (core dumped)
[[email protected] horrible-site]# php73 vendor/bin/phpunit
PHPUnit 7.5.1 by Sebastian Bergmann and contributors.

..39.014632940292.38.887251138687.42.945841789246Segmentation fault (core dumped)

Author: Woo Huiren

Currently a student at National University of Singapore. I contribute to opensource projects - primarily PHP and Angular related. I write about PCF and PWS related stuff too.

Leave a Reply