Skip to content

Read collected data with CollectedDataNode::iterate() - #489

Draft
janedbal wants to merge 1 commit into
masterfrom
jn-collected-data-iterate
Draft

janedbal wants to merge 1 commit into
masterfrom
jn-collected-data-iterate

Conversation

@janedbal

@janedbal janedbal commented Nov 6, 2026 •

Copy link
Copy Markdown
Member

Uses CollectedDataNode::iterate() from phpstan/phpstan-src#6963. The method yields the collected data of one analysed file at a time.

Do not merge before PHPStan 2.3.6 is tagged. Then change ^2.3.6@dev to ^2.3.6 and update the lock.

Until then, 9 e2e jobs fail on install: the projects in them have minimum-stability: stable, and @dev works only in the root package.

What changes

  • DeadCodeRule reads its 5 collectors with iterate(), not get().
  • The rule does not keep all collected data as arrays, and it does not merge the 4 usage arrays with array_merge_recursive().
  • The rule reads the usages collector by collector, not file by file. The order of the usages does not change the result. All tests pass without changes.
  • phpstan/phpstan is now required at ^2.3.6, because iterate() does not exist in older versions. Use AnalysisResult::withFileSpecificErrors() instead of constructor #297 also raised the minimum to use a new API.

Measurements

A large private codebase (~30k analysed files), run without changed files (a warm result cache). Peak memory of the main process and wall time. Details are in phpstan/phpstan-src#6963.

PHPStan 2.3.5, DCD 1.4.2 PHPStan with #6963, DCD with iterate()
offloadCollectorData: false 4.89 GB, 28 s 3.18 GB, 27 s

For comparison: offloadCollectorData: true (the default) with PHPStan with #6963 and DCD without iterate() used 3.28 GB, 28 s.

With iterate(), keeping the usages in the collected data takes less memory than the offload store does. A full analysis is different: the fresh data from the workers is still in memory in the main process, so false used 4.73 GB against 3.98 GB with true. This PR does not change the default.

Co-Authored-By: Claude Code

DeadCodeRule reads its 5 collectors with iterate() instead of get().
iterate() yields the values of one analysed file at a time. The rule
no longer holds all collected data as arrays, and it does not merge
the usage arrays with array_merge_recursive().

The rule now reads the usages collector by collector, not file by file.
The order of the usages does not change the result.

iterate() is new in PHPStan 2.3.6 (phpstan/phpstan-src#6963).

Co-Authored-By: Claude Code
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.

1 participant