Originally published at hafiz.dev
Pun, built by Pushpak Chhajed, wants to replace six tools with one binary. It formats like Pint and PHP-CS-Fixer, analyses like PHPStan and Larastan, refactors like Rector and installs packages like Composer, all from one Rust executable and one pun.toml. Nuno Maduro called it "bun, but for php" when it went into public beta in late November.
Most results I'd seen came from small sample projects. So I ran Pun 0.4.4 on a copy of Prompt Optimizer, a production Laravel 13 app with about 440 PHP files of its own and 944 tests, next to the tools it wants to replace. I timed everything, diffed the output and ran the test suite on both vendor/ folders.
Formatting is a clear win. Installs are faster once the cache is warm. The analyser is the part I wouldn't swap yet.
What I tested
- The app. A copy of Prompt Optimizer at Laravel 13.38, with about 440 PHP files and 49,000 lines outside
vendor/, and 179 packages inside it. - The machine. Apple M1 Pro, 8 cores, 16 GB of memory, PHP 8.3.
- The incumbents. Pint 1.32.1, the version locked in the app, with the default Laravel preset (the app has no
pint.json), Larastan 3.15.0 on PHPStan 2.3.7 at level 5 onapp/, and Composer 2.11.3. The app ships with Pint only, so I added Larastan for this comparison. - The challenger. Pun 0.4.4, installed through Composer.
I ran each command five or six times and quote the median of the runs after the first. Every number and every output block below is real.
composer require --dev shipfastlabs/pun vendor/bin/pun --version pun: downloading https://github.com/shipfastlabs/pun/releases/download/v0.4.4/punphp-aarch64-apple-darwin.tar.gz pun: verified the GitHub build attestation pun 0.4.4 The Composer package is a small PHP shim. On first run it downloads the binary for your platform into vendor/bin, checks its SHA-256 checksum and, with a signed-in gh, the GitHub build attestation. That binary is 83 MB. And because it lives in vendor/bin, every fresh vendor/ downloads it again. I watched it happen each time I rebuilt vendor/ for the install tests. In CI, cache it or use the standalone installer, which puts the binary in ~/.pun/bin.
pun migrate wrote the config in a tenth of a second
vendor/bin/pun migrate --dry-run pun migrate: dry-run, starter pun.toml to write (preset laravel, 115 format rules, 15 lint rules), ignore comments to rewrite in 0 files (0.09s) phpstan.neon migrate phpstan.neon unsupported format/functions/backtick-to-shell-exec: a PHPStan check that is this format rule in Pun; turn it on in [format.rules] The real run took 0.06 seconds. It read composer.lock, switched on the Laravel, PHPUnit, Carbon and Mockery extensions, and turned PHPStan level 5 into a preset:
[extensions] laravel = "on" phpunit = "on" carbon = "on" mockery = "on" [format] preset = "laravel" [analyse] preset = "phpstan/level_5" paths = ["app"] It also wrote 15 lint rules from Pint's Laravel preset, and moved 9 PHPStan level 5 checks, such as duplicate array keys, into lint for app/. One check didn't map, and the output tells you which one.
One warning before you run it on your own project. pun migrate rewrites @phpstan-ignore and @php-cs-fixer-ignore comments in your PHP files to @pun-ignore. My app had none. Yours might, so start from a clean working tree.
Formatting is 35 times faster, with the same bytes
Check mode on the whole project, no files changed:
| Command | Median |
|---|---|
vendor/bin/pint --test | 2.82 s |
vendor/bin/pint --test --parallel | 1.30 s |
vendor/bin/pun format --test | 0.08 s |
Pint's --parallel flag is still marked experimental, and Pun beats it 16 to 1. Against plain Pint it's 35 to 1. The 0.08 seconds includes booting the PHP shim. Calling the binary directly took 0.03 seconds.
Speed means nothing if the output differs, though. The codebase had drifted from Pint's current rules, and both tools flagged the same 63 files. So I let each one fix them on its own branch and diffed the branches:
git checkout -b pint-fix && vendor/bin/pint && git commit -qam "pint" git checkout main && git checkout -b pun-fix && vendor/bin/pun format && git commit -qam "pun" git diff --stat pint-fix pun-fix The diff was empty. Both branches changed 63 files with 215 insertions and 125 deletions, and pint --test passes on Pun's output. Byte for byte, as the README promises.
One person on a team can move to Pun without the formatter fighting everyone else in every pull request.
Analysis matched 131 of 136 findings after one config change
With default settings, Larastan found 223 errors in app/, and Pun, on the config pun migrate wrote, found 221. I matched them on file, line and error identifier. 209 were identical, 14 came from Larastan only and 12 from Pun only. Then I looked at what the differences had in common.
Both analysers misread casts() by default
Seven of Pun's 12 extra findings had the same shape. Here's one:
protected function casts(): array { return [ 'tags' => 'array', // ... ]; } public function getTagsStringAttribute(): string { return is_array($this->tags) ? implode(', ', $this->tags) : ''; } app/Models/Post.php:180 analyse/dead-code/impossible-type-check Call to function is_array() with string|null will always evaluate to false. app/Models/Post.php:180 analyse/types/argument Parameter #2 $array of function implode expects array, string|null given. The tags column is $table->json('tags')->nullable(). Both tools typed it from the migration as string|null and ignored the array cast. Larastan reports the is_array() line too. It stops there because it treats the implode() branch as unreachable, while Pun reports both lines.
Larastan builds the model without running its constructor, so getCasts() never sees casts(). By default it only reads the declared return type of casts(), which is plain array. The parseModelCastsMethod option parses the method body instead, and it's off by default because parsing is slower. Pun copies that default. That's a trap for any app written since Laravel 11, because the Laravel docs have shown casts as a method since then.
So I switched it on in phpstan.neon:
includes: - vendor/larastan/larastan/extension.neon parameters: paths: - app/ level: 5 parseModelCastsMethod: true Then I ran pun migrate again. It carried the setting over as an option on two Laravel rules:
[analyse.rules] "laravel/redundant-collection-call" = { parse-model-casts-method = true } "laravel/undefined-model-append" = { parse-model-casts-method = true } Larastan dropped from 223 errors to 136, and Pun from 221 to 133. Of those, 131 matched. One default had produced 87 of Larastan's 223 errors.
What's left after that
Five findings came from Larastan only:
- a
?->onauth()->user()after an earlier check already proved the user exists - a property read through a relation typed as the base
Modelclass - two
str_contains()checks on an error message that Larastan proved can never match - an array passed to the Stripe SDK that doesn't match the SDK's documented array shape
Two came from Pun only. One is a read of $post->tags inside an ! empty() check, which narrows the type for Larastan but not for Pun. The other is a match on a string the code validates earlier with in_array(), which Pun flags as not exhaustive and Larastan doesn't.
None of them is exotic. The analyse docs are upfront that some PHPStan and Larastan checks are still marked Planned.
Speed depends on the result cache
With casts read in both tools:
| Command | Median |
|---|---|
| Larastan, result cache cleared | 3.32 s |
| Larastan, warm result cache | 1.06 s |
pun analyse | 1.70 s |
pun check (format, lint and analyse) | 1.69 s |
Parsing casts() didn't make Larastan measurably slower. The cold run took 3.32 seconds with it and 3.26 without.
A warm Larastan was faster than Pun, though. PHPStan's result cache only analyses the files that changed since the last run, plus the files that depend on them. Pun took between 1.69 and 1.76 seconds on every run after the first, with no cache effect I could see. Its docs say it reads vendor/ for classes and functions, and this vendor/ holds almost 20,000 PHP files.
So the fair comparison depends on where you run it. On a CI runner that doesn't restore the PHPStan cache between runs, Pun is almost twice as fast. On your laptop after the first run, Larastan wins. (I covered what each Larastan level catches in running Larastan at every level on agent-written code.)
Lint found one real bug
pun lint with the migrated rules took about a second and reported 10 problems in 8 files, all with safe fixes:
- 6 redundant nullsafe operators (
?->on values that can't be null) - 3 private constants that nothing reads
- 1 duplicate array key
The duplicate key is a real bug. An array of prompts had the key 'literary critic' twice, so the first value was silently lost. Larastan reports it too, but in a list of 136 errors it's easy to scroll past. Pint never looks at this kind of thing, because it only formats.
Before you run pun lint --fix across a whole codebase, read the open issues. One of them, #32, reports a rule that removes an integer cast the code needs and causes a TypeError. My migrated config didn't trip it.
Installs are faster warm and a tie cold
I used Composer 2.11.3, the release line with the cooldown I tested in November. For the first and last rows I deleted vendor/ before each run:
| Scenario | Composer 2.11.3 | pun install |
|---|---|---|
| Warm cache | 6.24 s | 4.11 s |
| Nothing changed | 3.09 s | 0.62 s |
| Empty cache | 12.7 to 14.4 s | 10.8 to 15.2 s |
An empty cache means downloading every package, so the network decides. The ranges overlap. I call it a tie.
Pun prints where its time goes:
+ packages: 179 installed (179 from the cache) + autoloader: 15024 classes Installed in 3.9s (Pun 3.3s, Composer scripts and plugins 0.6s) Pun still runs your Composer scripts, and they still need PHP. Here that's package:discover and filament:upgrade, which take 0.6 seconds, and that's the whole of the no-op install. Composer's no-op dumps the autoloader again and runs the same scripts, and takes 3.09 seconds.
Then I checked the result. I ran the full PHPUnit suite once on Composer's vendor/ and once on Pun's. All 944 tests had the same outcome, test by test. (The copy had no built front-end assets and no production API keys, so the same 110 tests failed on both.)
One trade-off from the install docs. Pun hardlinks packages from a shared store by default, so editing a file in vendor/ edits it in every project that shares that package. If you patch vendor files while debugging, set --link-mode=copy.
What I'm switching
- Formatting moves to Pun now. It's byte-identical to Pint, and the pre-commit hook stops being something I wait for.
pun check --dirtytook 1.2 seconds on one changed file, against 1.8 seconds forpint --dirtyplus Larastan on that file. (If the hook also runs tests, Pest's test impact analysis keeps that part short.) - Larastan stays in CI. Five misses and two extras are close, but the tool that blocks a merge has to catch everything the old one did. I'll run the comparison again on the next Pun release.
-
pun installis for local work. The 0.6-second no-op is the install I hit dozens of times a day. CI and deploys stay on Composer while Pun is in beta, since a cold install isn't faster anyway.
And pin the version. The installation docs still show 0.2.7 in their example, and I installed 0.4.4 a few days after launch. This thing moves fast.
FAQ
Can Pun replace Pint without changing my code style?
On this app, yes. Both tools changed the same 63 files in exactly the same way, and Pint passed on Pun's output. There are limits. Pint's symfony preset isn't supported, and custom rules or closures in your Pint config are skipped with a warning.
Does Pun need PHP installed?
Not for format, lint and analyse. pun install still runs your Composer scripts, which need PHP, and migrating a rector.php or .php-cs-fixer.php file needs PHP and that tool.
Is pun analyse a drop-in replacement for Larastan?
Not yet. With parseModelCastsMethod on in both tools, it matched 131 of Larastan's 136 findings on a real Laravel 13 app at level 5, missed 5 and added 2. Without that option both tools misread casts(), so compare them with it on.
Is pun install faster than composer install?
With a warm cache it took 4.1 seconds against 6.2. When nothing changed it took 0.6 seconds against 3.1. With an empty cache both are limited by the network and took about the same time.
Why does Pun add 83 MB to vendor/?
The Composer package is only a PHP shim. On first run the shim downloads the native binary for your platform into vendor/bin, and that binary is 83 MB. Every fresh vendor/ repeats the download unless you cache it or install Pun globally.
Turn on parseModelCastsMethod first
If your models declare casts in a casts() method, Larastan and Pun both ignore them until you set parseModelCastsMethod: true in phpstan.neon, which pun migrate carries into pun.toml. On this app that one line removed 87 of Larastan's 223 errors, and it didn't make the cold run measurably slower. Set it before you compare analysers, and before you trust either one.
