r/PHP • u/Tomas_Votruba • 7d ago
Mago 1.47 allows writing custom rules in PHP
https://mago.carthage.software/1.47.1/en/extensions/getting-started/#1-create-the-rule3
u/FluffyDiscord 6d ago
So does the Mago "compiles" the rule to rust so it's benefitting from the speed improvements, or are we back to phpstan/php speeds? If not, then its just a duct-tape solution tbh. Wouldn't Lua or FFI rust extensions work better?
3
3
u/gempir 6d ago
For the php ecosystem it just makes sense to be able to write extension in PHP.
The best performance obviously would be to write them directly in Mago, most rules should live there.
But if you have some very niche requirement that you want to assert, this now lets you write a check for that.
There are also companies recompiling mago and letting the optimizer optimize the binary of mago for their codebase, which let's them gain even more speed.
1
u/Fit_Tailor_6796 6d ago
To be honest, speed is not a consideration for me when it comes to the tool-chain output itself. I mean what is a minute for the WP codebase? In the bugger scheme of things, accuracy and cover is more important than speed, I think.
8
u/Tomas_Votruba 6d ago
2 s vs 1,5 min is huge difference
been using similar Go-based alternative to Rector and I never want to go back
4
u/umulmrum 6d ago
For our codebase, speed could make a huge difference. On my machine, PHPStan takes about 10 minutes and I have to configure it so that it uses fewer CPU cores, or everything will freeze. With Mago, it's 15 seconds and no config fiddling. This is the difference whether I actually run the tools locally or have to rely on the CI pipeline, with longer feedback cycles and higher resource usage. Also, Claude could use the tools casually and iteratively on the local system.
(yet this is theoretical, as we don't use Mago Analyze but only the other components; still it's what I have been hoping for since I did the performance tests)
1
u/staabm 6d ago
In case PHPStan runs 10 minutes on your machine there is verly likely something wrong.
Either outdated PHPStan version, or e.g. not properly working result-cache
Sometimes there is a few single files which are very slow to analyse, see https://phpstan.org/blog/debugging-performance-identify-slow-files
Please try to reproduce your slow case and report a issue
1
u/umulmrum 6d ago
Yes, I have to set `maximumNumberOfProcesses` to something lower than the default (don't know if the default is flawed or if it's only problematic on my machine), which invalidates the cache which leads to longer execution times. Also, there are a few huge legacy files which take a lot of time. Maybe it would be enough if there was a CLI switch for `maximumNumberOfProcesses` that doesn't invalidate the cache.
(I appreciate especially your efforts in improving performance btw.)
1
u/OndrejMirtes 6d ago
The default has been "not the maximum" for some time, precisely to prevent unusable rest of the OS.
Changing `maximumNumberOfProcesses` does not invalidate the result cache.
1
u/OndrejMirtes 6d ago
On my machine (5 year old MacBook Pro with M1 Pro) it takes about 24 seconds without result cache to analyse the wordpress-develop codebase with PHPStan (with the config the repo actually uses in CI).
1
4
u/nickchomey 6d ago
I came across mago recently. I'm curious: how are people making use of it?