Skip to content

Report worker peak memory when the result cache is used - #6576

Merged
staabm merged 2 commits into
phpstan:2.2.xfrom
alfredbez:2.2.x
Sep 24, 2026
Merged

staabm merged 2 commits into
phpstan:2.2.xfrom
alfredbez:2.2.x

Conversation

@alfredbez

Copy link
Copy Markdown
Contributor

With -vvv, PHPStan prints the peak memory of the main process and of the largest worker. When the result cache is partly restored, the worker part is missing, even though workers ran.

Cold run on 4 files:

Peak memory: 26 MB (main process), 28 MB (largest of 2 forked workers)

Next run after changing 2 of them:

Peak memory: 14 MB

ResultCacheManager::process() rebuilds the AnalyserResult for this case and does not pass workerCount. It falls back to 0, so InceptionResult prints only the main process. AnalyseApplication::switchTmpFileInAnalyserResult() drops it the same way in editor mode. Both came with #6297. The fix passes workerCount through in both places. I did not add a test for editor mode.

The first commit only adds an e2e test. I pushed the two commits one after the other to 2.2.x in my fork, so you can see the test fail before the fix:

Feel free to squash.

When only some files are analysed again, -vvv shows only the main
process's peak memory and drops the workers' peak. This test fails
until that is fixed.
When only some files were analysed again, the result was rebuilt from the
result cache without the worker count. -vvv then showed only the main
process's peak, even though workers had run. Editor mode rebuilt the result
the same way.
@staabm

staabm commented Sep 24, 2026

Copy link
Copy Markdown
Contributor

//cc @SanderMuller please review :)

@SanderMuller SanderMuller left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, this looks good.

  • With the fix, the second run of the e2e fixture prints Peak memory: 14 MB (main process), 22 MB (largest of 2 forked workers). With the base src it prints only Peak memory: 14 MB.
  • I also checked editor mode by hand, with --tmp-file/--instead-of after a partial restore. It shows the worker line with the fix, and loses it again when only the AnalyseApplication.php change is reverted.
  • The other new AnalyserResult(...) calls without workerCount are the empty-file and non-parallel paths, where 0 is correct. So these two are the only copies.
  • The full suite, make phpstan and phpcs on both files pass. Warm-run CPU on a real project is the same, 1.64–1.67 s before and 1.64–1.75 s after.

The three reds that other 2.2.x PRs do not have are not from this change. The phpbench harness does not reach ResultCacheManager or AnalyseApplication, and the two jobs fail on different variants. The IntersectionTypeTest::testIsAcceptedBy failures on Windows with old PHPUnit also happened today on two unrelated 2.3.x PRs.

@staabm
staabm merged commit 6e0238d into phpstan:2.2.x Sep 24, 2026
863 of 877 checks passed
@staabm

staabm commented Sep 24, 2026

Copy link
Copy Markdown
Contributor

Thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants