Don't use parallel analyser if it doesn't save time #2831
Closed
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.
After doing a bit of a deep dive into the performance of PHPStan and where most of the bottlenecks live, I found that quite a large chunk of time is spent in launching the PHPStan process, which consists of processing arguments (~130ms), finding to-check files (~250ms), building container factories (~750ms) among others. (These are the times taken for our codebase, I can share these stats in more detail if you'd like).
After realizing that (depending on the project config of course) about 1s is spent just on launching the parallel-mode subprocess I figured it might be a good idea to disable parallel mode if it's not "worth it", meaning it'll only end up checking a single file.
I think that this change will help speed up PHPStan because (at least in our codebase) it shaves off 1s from any single-file change. As you can imagine this is quite massive especially when using PHPStan pro.
It could be that this number can be bumped up a little more even, maybe checking 2 files in a row is faster than parallelizing it, but I can't definitively say that because it might differ from codebase to codebase so I'll keep the check at 1 file in this PR.