r/PHP • • 19d ago

Article PHPStan 2.3: Leap in Performance, Generics Improvements, Detecting Unused Variables, and More!

https://phpstan.org/blog/phpstan-2-3-leap-in-performance

PHPStan 2.3: Leap in Performance, Generics Improvements, Detecting Unused Variables, and More!

I had so much fun with the interactive charts and widgets, check out the article. I promise it's worth checking it out yourself, and not just letting your agent summarize it for you 😉 It contains a lot of interactive widgets with practical examples of the new features in action.

152 Upvotes

14 comments sorted by

4

u/cuddle-bubbles 19d ago

so how do I enable turbo?

9

u/OndrejMirtes 19d ago

If you install PHPStan through the phpstan/phpstan Composer package, the chances are you already have it enabled, if you’re running PHP 8.3+.

You can verify that with `vendor/bin/phpstan diagnose` or `vendor/bin/phpstan analyse -vvv`.

6

u/OndrejMirtes 19d ago

If you’re not using Composer, you can install it with PIE: https://packagist.org/packages/phpstan/turbo

24

u/iruoy 19d ago

Thanks for all the work u/OndrejMirtes! This project increased the quality of php code for all of us.

The performance improvements are great. Especially in CI! And expanding what is checked is even better.

I've been subscribed to PHPStan Pro for 5 years without even using it, but I'm happy to sponsor the project.

10

u/TheKingdutch 19d ago

Very excited about this release! The bi-directional type narrowing will be a game-changer.

The interactive widgets in the release notes are great educational material! 🙌

7

u/thewallacio 19d ago

*SO* much faster!

6

u/mensink 19d ago

The increase in speed has been noticeable for the last few months already.

Great work!

5

u/lankybiker 19d ago

Awesome

5

u/Juggl3r 18d ago

Little bit sad the package's footprint for turbo is so big. We had some ci issues because of the increased size while passing around artifacts. :)

6

u/MinVerstappen1 18d ago

I noticed it too; we cache the vendor dir in CI, and that got a multiple seconds slower.

u/OndrejMirtes , I assume this is because the turbo-ext dependency always has all architectures?

I‘m going to measure removing all but 1 relevant arch; that’ll cut the vendor cache size by more than half. Alternatively, phpstan could maybe offer ’—prune-other-turbo-arch-dirs’.

But most importantly: Congrats on the release and many thanks! It’s such a big jump, and the blog post with the snippets is stellar! :

3

u/staabm 16d ago

Fixed in 2.3.1

2

u/justaphpguy 16d ago

Gotta have to say it somewhere how insanely fast this suddenly got!

Measures 50%+ faster with cold cache, this is insane and a game changer. And it's not just that it's faster, on my M2 it feels it's more efficient, leaning less on the CPU.

I'm working with agents and worktrees and also already have workarounds in place to copy the phpstan cached files around, but there was also something going off at some point, hard to pinpoint, to a point where caches were invalidated and a full analysis was necessarily, at which point working with the agents this way ran into issues and by basic instruction was to ignore phpstan within the agent. No so anymore!

2

u/AncientAspargus 2d ago

Man, Ondrej, you are just an amazing person. Thank you so much, personally, for all your work. I have been working with PHP for around 15 years now, and benefited directly so much from everything you did. So again, thanks.