Fetching comments from Joind.in..."); $anchor.slideDown("slow", function(){ $.get("php/joindin.php", { id: $(this).attr('jid') }, function(data){ $anchor.slideUp("fast", function(){ $anchor.html(data); $anchor.slideDown("slow"); }); }); }); } else { $(this).parent().next().slideToggle("slow"); } }); $("p a.show-comments").attr("href", "#nothing"); $(".talk-comments").hide(); $("img#logo-image").mouseover(function(){ opacity = 1; step = -0.01; setTimeout( 'nextAnim()', 2500 ); }); hash = self.document.location.hash.substring(1); if (hash) { $("." + hash).show(); } }); $(document).ready(function() { let containers = document.getElementsByClassName("slideshow-container"); for (i = 0; i < containers.length; i++) { containers[i].dataset.slideIndex = 1 showSlides( containers[i].id ) } }) function plusSlides(id, plus) { let container = document.getElementById(id); container.dataset.slideIndex = parseInt( container.dataset.slideIndex ) + plus; showSlides(id); } function showSlides(id) { let container = document.getElementById(id); let n = container.dataset.slideIndex let i; let slides = container.getElementsByClassName("mySlides"); if (container.dataset.slideIndex > slides.length) { container.dataset.slideIndex = 1 } if (container.dataset.slideIndex < 1) { container.dataset.slideIndex = slides.length } for (i = 0; i < slides.length; i++) { slides[i].style.display = "none"; } slides[parseInt(container.dataset.slideIndex) - 1].style.display = "block"; }

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.

Shortlink

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

Comments

Curious if providing argument and return types and specifying strict_types would increase performance? Doing so would allow PHP to bypass a lot of the dynamic type magic, no? Likely not a huge increase but maybe enough to put it over the 50% mark?

Add Comment

Name:
Email:
Will not be posted. Please leave empty instead of filling in garbage though!
Comment:
Please follow the reStructured Text format. Do not use the comment form to report issues in software, use the relevant issue tracker. I will not answer them here.

All comments are moderated
Become a Patron!
Mastodon
GitHub
LinkedIn
RSS Feed
Flickr
YouTube
Vimeo
Email

My Amazon wishlist can be found here.

Life Line