Repository navigation
Let another program that loads the phar use PHPStan Turbo - #6720
Open
SanderMuller wants to merge 1 commit into
Open
SanderMuller wants to merge 1 commit into
SanderMuller wants to merge 1 commit into
Conversation
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Rector loads PHPStan's phar from
vendor/phpstan/phpstan, and it gets a lot faster with PHPStan Turbo. On rector-src with its ownrector.php, Rector takes 7.9 s instead of 11.8 s, and 60 s of CPU instead of 98 s. Those are medians of 5 cold runs with 14 workers, on an M4 Pro with PHP 8.5. Rector calls the API below, with a phar built from this branch. The output is the same with and without Turbo.To get there, Rector needs the same three calls as
bin/phpstan. But these calls find the phar throughPhar::running(), which is empty when Rector is the script that runs.This adds an optional
?string $pharPathtoTurboProcessRestarter::restartIfSuitable(),TurboExtensionEnabler::trustOwnTypesIfSuitable()andTurboExtensionEnabler::activateIfCompatible(), and toTurboExtensionSelector::findExtension()andfindExtensionForWorkers(), which they call. Without the argument, nothing changes. The three methods that another program calls are now@api. A path that is passed in goes throughrealpath(). Code compiled from the phar carries the resolved path that Composer'sbootstrap.phpopens it with. Withoutrealpath(), a path likebin/../vendor/...switches trusted types on, but they have no effect.tests/bootstrap.phpcallsactivateIfCompatible(), so itsphpstanApi.methodignore is not needed any more.Rector would call them right after its Composer autoloader:
Its workers start as new processes, so each of them restarts once in the same way. I checked the main process and all 14 workers. In each one the extension is active and OPcache is on. A class-typed parameter check in the phar is dropped, the same as inside PHPStan. With Rector's
--debug, the checks stay, like with PHPStan's.Rector needs two changes of its own. One is merged: rectorphp/rector-src#8564 removes extra arguments to the
TypeTraversercallback, which the native callback rejects. The other is still to do: Rector'spreload.phpmust skipPhpParser\NodeTraverserwhen Turbo has already declared it.make testsandmake phpstanpass, and phpcs reports no errors on the changed files.🤖 Generated with Claude Code