Skip to content

[perf] Run the workers with PHPStan Turbo - #8812

Open
SanderMuller wants to merge 3 commits into
rectorphp:mainfrom
SanderMuller:turbo-in-workers
Open

SanderMuller wants to merge 3 commits into
rectorphp:mainfrom
SanderMuller:turbo-in-workers

Conversation

@SanderMuller

@SanderMuller SanderMuller commented Oct 24, 2026 •

Copy link
Copy Markdown
Contributor

Runs Rector's workers with PHPStan Turbo, the native extension that ships with phpstan/phpstan.

  • WorkerCommandLineFactory passes the extension to the workers with -d. The workers do the analysis, so the main process does not restart.
  • bin/rector activates Turbo before preload.php, because Turbo replaces php-parser classes. When Rector is installed as a dependency, bin/rector loads PHPStan's bootstrap early, because the project autoloader comes after preload.php.
  • Requires phpstan/phpstan ^2.3.2 for TurboExtensionSelector::EXTENSION_PATH_INI.
  • The Self Benchmark workflow runs Rector on its own rules/ for the base and for the PR. The job summary shows both.
Shopware v6.7.6.2, cold --dry-run main this PR
CPU time 256.9 s 128.4 s (-50%)
Wall time 41.3 s 30.4 s (-26%)

Medians of 5 interleaved runs per side, with Shopware's own rector.php, on an M4 Pro with PHP 8.5. Every run gave the same 14 changed files.

The first version of this PR also restarted the main process into Turbo. That made warm runs slower and cold runs no faster, so I removed it. Forking workers comes in a separate PR, and it will probably need the restart back.

@TomasVotruba

Copy link
Copy Markdown
Member

Thanks 👍

Can you add simple CI workflow that would run Rector on itself and show numbers before/after? So we have a reproducible bench to adhere to.

@SanderMuller

Copy link
Copy Markdown
Contributor Author

Thanks 👍

Can you add simple CI workflow that would run Rector on itself and show numbers before/after? So we have a reproducible bench to adhere to.

I added the CI workflow, I'm still benchmarking locally if the main-process restart can/should be skipped, which will have impact on the warm benchmarks

@SanderMuller SanderMuller changed the title [perf] Restart into PHPStan Turbo and pass the extension to the workers [perf] Run the workers with PHPStan Turbo Oct 25, 2026
@SanderMuller

Copy link
Copy Markdown
Contributor Author

I added the Self Benchmark workflow. On this PR:

main this PR
cold wall 9.83 s 4.72 s
cold CPU 37.41 s 17.52 s
warm wall 0.30 s 0.31 s

The new Self Benchmark workflow runs scripts/rector-ab-benchmark.php on
Rector's own rules/ directory, first with the base branch and then with
the pull request, and puts the A/B table in the job summary. The script
now also reports the median CPU time, workers included.
The workers get Turbo on their command line, and they do the analysis.
The restart cost every warm run time and gave no cold gain.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

2 participants