Skip to content

Print the rules on CollectedDataNode in --debug output - #6723

Merged
ondrejmirtes merged 2 commits into
phpstan:2.3.xfrom
SanderMuller:debug-collected-data-rule-timing
Oct 28, 2026
Merged

ondrejmirtes merged 2 commits into
phpstan:2.3.xfrom
SanderMuller:debug-collected-data-rule-timing

Conversation

@SanderMuller

@SanderMuller SanderMuller commented Oct 9, 2026 •

Copy link
Copy Markdown
Contributor

Rules registered for CollectedDataNode run in the main process after all files are analysed. They run on every run, also when every file comes from the result cache. --debug prints each analysed file, and with -vvv its time and memory, but it prints nothing for these rules. When one of them is slow, the run only takes longer after the last file, and the output does not say why.

With dead-code-detector, a warm run on PHPStan's own src/ at level 0 takes about 1.24 s instead of 0.29 s (phpstan/phpstan#15447). Its rule alone takes 1.01 s in the output below. The progress bar does not show this phase either (phpstan/phpstan#8411).

With this change, --debug prints each of these rules the same way it prints files. With dead-code-detector 1.4.2 on PHPStan's src/ at level 0, --debug -vvv prints this after the list of files:

Running PHPStan\Rules\Methods\MethodCallWithPossiblyRenamedNamedArgumentRule on the collected data
--- consumed 0 B, total 614 MB, took 0.00 s
Running PHPStan\Rules\Comparison\ConstantConditionInTraitRule on the collected data
--- consumed 0 B, total 614 MB, took 0.00 s
Running ShipMonk\PHPStan\DeadCode\Rule\DeadCodeRule on the collected data
--- consumed 100.02 MB, total 714.02 MB, took 1.01 s

The --- consumed line needs -vvv, like the one after each file. Its time covers the rule's processNode(), not PHPStan's handling of the errors it returns. Without --debug nothing changes: AnalyseApplication passes no callbacks, and finalize() only adds two null checks per rule.

finalize() calls the second callback in a finally, so it also runs when a rule throws. AnalyserResultFinalizerTest checks that with and without --debug, and it fails without the change.

🤖 Generated with Claude Code

SanderMuller and others added 2 commits October 28, 2026 20:20
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@ondrejmirtes
ondrejmirtes force-pushed the debug-collected-data-rule-timing branch from 7dadacf to 0108bab Compare October 28, 2026 19:20
@ondrejmirtes
ondrejmirtes merged commit d78e176 into phpstan:2.3.x Oct 28, 2026
267 of 268 checks passed
@ondrejmirtes

Copy link
Copy Markdown
Member

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.

2 participants