PHP 8: A Quick Look at JIT
Following on from a PHP 8/JIT benchmark on twitter, I decided to have a look myself.
I've picked an example that I know speeds up really well when reimplementing it in C. I wrote about this RDP algorithm some time ago.
What it does is to take a line of geospatial points (lon/lat coordinates), and simplifies it. It's my go-to example to show raw algorithmic performance, which is probably the best place to use a JIT for non-trivial code. I actually use this in production.
With PHP 7.4:
$ pe 7.4dev; time php -n \
-dzend_extension=opcache -dopcache.enable=1 -dopcache.enable_cli=1 \
-dopcache.jit=1235 -dopcache.jit_buffer_size=64M \
bench-rdp.php 1000
Using array (
0 => 'RDP',
1 => 'simplify',
)
real 0m8.778s
user 0m8.630s
sys 0m0.117s
(I realise that the opcache arguments do nothing on the command line here). This runs RDP::simplify (my PHP implementation) 1000 times in about 8 seconds.
With PHP 8.0 and JIT:
$ pe trunk; time php -n \
-dzend_extension=opcache -dopcache.enable=1 -dopcache.enable_cli=1 \
-dopcache.jit=1235 -dopcache.jit_buffer_size=64M \
bench-rdp.php 1000
Using array (
0 => 'RDP',
1 => 'simplify',
)
real 0m4.640s
user 0m4.627s
sys 0m0.008s
It jumps from ~8.8s to ~4.6s, a reduction in time of ~4.2s (or 48%), which is pretty good.
Now if I run the same with the geospatial extension which has a C implementation.
With PHP 7.4 and the extension:
$ pe 7.4dev; time php -n -dextension=geospatial \
-dzend_extension=opcache -dopcache.enable=1 -dopcache.enable_cli=1 \
-dopcache.jit=1235 -dopcache.jit_buffer_size=64M bench-rdp.php 1000
Using 'rdp_simplify'
real 0m0.695s
user 0m0.675s
sys 0m0.021s
Which gives a reduction in speed compared to PHP 7.4 of ~8.1s (or 92%).
So it looks like the JIT does do some good work for something that's highly optimisable, but still nowhere near what an implementation in C could do.
The code that I used is in this Gist.
This ran on a 4th gen ThinkPad X1 Carbon, making sure my CPU was pinned at its maximum speed of 3.3Ghz. Although I've pasted only one result for each, I did run them several times with very close outcomes.
Life Line
Merged pull request #1049
Reorder xdfree(name) and removing trailing whitespace
Tweak comments to use /* .. */ style
Reuse created \\.\pipe name
Change log level for failing SetNamedPipeHandleState
It must be the first of the month, because the GitHub sponsor cancellations are coming in again.
Instead of spending money on things that you don't need on this #cybermonday, support the maintainers of the open source projects who help you create the software that powers your site.
For @Xdebug that could be through:
- GitHub sponsors: https://github.com/sponsors/derickr
- Directly with an invoice: https://xdebug.org/support
- Signing up and using Xdebug Cloud: https://xdebug.cloud/It was a great morning for a walk along the Thames' North Bank. Curiously, I had never really walked this stretch of it before.
Store the control_socket_path internally without the platform specifi…
I hiked 8.3km in 1h31m39s
I hiked 16.0km in 2h48m42s
I walked 1.6km in 15m21s
📷 Fly Agaric
🚩 Lange Juffer, Ellecom, Nederland
📷 South Downs Way
🚩 Wealden, United Kingdom
I walked 3.1km in 32m52s
I walked 6.0km in 1h4m00s
Where in the UK's autumn budget they're freezing fuel duty again, in the Netherlands they're planning to increase it by 5¢/l, and use the money raised for public transport:
Benzine ruim 5 cent duurder door belastingverhoging, geld gaat naar openbaar vervoer - https://nos.nl/l/2592206
I walked 7.7km in 1h24m33s
I walked 1.1km in 9m48s
Fix wrong usage of SetNamedPipeHandleState and log possible errors wh…




Shortlink
This article has a short URL available: https://drck.me/jit1-fmy