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
I know my French is pretty terrible, but I'm sure I'm closer to the correct answer than what's shown here...
Merge branch 'v2022'
Merge pull request #169 from psumbera/solaris-2
I walked 7.0km in 1h6m48s
Fixed some ffing sidewalks again.
I walked 10.5km in 1h40m26s
Updated a pet_grooming shop
I walked 8.6km in 2h12m58s
I walked 8.7km in 1h24m16s
Updated a restaurant
I walked 2.4km in 24m20s
I walked 6.6km in 1h4m32s
I walked 0.6km in 4m38s
I walked 8.5km in 1h22m35s
Merged pull request #1029
Reflow some comments
Add comments, add end of file newlines, fix php 8.5 compilation
Benchmark Xdebug performance
Merged pull request #1051
PHP 8.6: printf() is now optimised out if it only uses %s and %d (and…
PHP 8.6: The object IDs of objects changed in tests
PHP 8.6: ZSTR_INIT_LITERAL() no longer takes non-literals, so use zen…
PHP 8.6: WRONG_PARAM_COUNT has been removed in favour of zend_wrong_p…
PHP 8.6: zval_dtor() has been deprecated in favour of zval_ptr_dtor_n…
Update test for version constraints, as well as the error messages


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