Repository navigation
Reuse the errors of rules on CollectedDataNode from the result cache - #6840
Open
SanderMuller wants to merge 2 commits into
Open
SanderMuller wants to merge 2 commits into
SanderMuller wants to merge 2 commits into
Conversation
ResultCacheManager::process() now returns the save as a callback, and both callers call it after AnalyserResultFinalizer::finalize(). Nothing else changes: the same data is saved. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
CollectedDataNode records which collectors a rule reads and whether it reads isOnlyFilesAnalysis(). The result cache stores the errors of each rule with a hash of that input. On the next run, a rule whose input is the same returns its stored errors and does not run again. The ignore extensions and the local ignores still run on every error, also on reused errors. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
SanderMuller
force-pushed
the
cache-collected-data-rule-errors
branch
from
October 25, 2026 20:23
b36b4f2 to
b6b5518
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
This follows the design from phpstan/phpstan#15447 (comment).
The rules on
CollectedDataNodenow run again only when their input changed.CollectedDataNoderecords which collectors a rule reads withget(), and whether it callsisOnlyFilesAnalysis(). The result cache stores the errors of each rule with a hash of that data. On the next run, a rule with the same input gets its stored errors back.The ignore extensions and the local ignores still run on every error, also on reused ones. A rule that throws is not stored, so it runs every time. Each rule gets its own
CollectedDataNode, so a service that memoizes per node cannot hide a read from the next rule.To store the rule results, the result cache is now saved after the finalizer ran. That is the first commit.
PHPStan self-analysis with dead-code-detector (
build/phpstan.neon, 13 errors in both arms):Warm rows are the median of 5 rounds, cold of 9 rounds in both orders. The result cache grows from 39.4 MB to 39.7 MB.
A rule can also depend on data the node does not see. larastan's
UnusedViewsRulereads the Blade view files from disk. A new unused view does not change the collected data, so this PR can return the old errors. I did not run larastan with this PR. Should the reuse be opt-in for third-party rules, or opt-out with an interface or attribute? I can change it either way.This overlaps with #6373, which loads the cached collected data only when the rules run. This PR hashes the collected data on every warm run, so it reads it every time.
Refs phpstan/phpstan#15447
🤖 Generated with Claude Code