Skip to content

[perf] Fork parallel workers from the main process when PHPStan Turbo is loaded - #8929

Open
samsonasik wants to merge 5 commits into
mainfrom
perf-pcntl-fork
Open

samsonasik wants to merge 5 commits into
mainfrom
perf-pcntl-fork

Conversation

@samsonasik

@samsonasik samsonasik commented Nov 12, 2026 •

Copy link
Copy Markdown
Member

This PR improve parallel process performance by using pcntl_fork when possible, as a forked worker is a copy of the already initialized PHP process, so it can start working right away, see my post at dev to that I applied the performance improvement on StructArmed via pcntl_fork when possible:

https://dev.to/samsonasik/structarmed-fast-php-architecture-guards-you-can-rely-on-3be3#an-even-faster-parallel-process

Measured with bench/parallel_memory_bench.php, 8 workers, 3 cold runs each, PHP 8.4, same php.ini with PHPStan Turbo loaded on both sides:

Project Metric main (spawned workers) this PR (forked workers)
CodeIgniter4 system CPU (user+sys) 19.1–20.0 s 16.6–17.0 s
Peak total RSS 2125–2210 MiB 1974–2017 MiB
Peak single worker RSS 294–314 MiB 274–281 MiB
Changed files (fingerprint) 257 257
spiral-framework src CPU (user+sys) 11.9–12.6 s 9.7–9.8 s
Peak total RSS 1812–1889 MiB 1693–1720 MiB
Peak single worker RSS 244–258 MiB 231–236 MiB
Changed files (fingerprint) 137 137

Without PHPStan Turbo loaded in the main process, workers are still spawned and nothing changes.

@samsonasik

Copy link
Copy Markdown
Member Author

@TomasVotruba ready 👍

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.

1 participant