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
SanderMuller
force-pushed
the
cache-collected-data-rule-errors
branch
from
October 25, 2026 20:23
b36b4f2 to
b6b5518
Compare
Member
|
This is nice but I worry it's also a BC break. Users before expect that CollectedDataNode rules always run. A few ideas:
|
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. A rule can declare what else it reads with the DependencyTracker methods, for example trackFileDependency() or trackDirectoryDependency(). These values are stored with its errors, and the rule runs again when one of them changes. The ignore extensions and the local ignores still run on every error, also on reused errors. This is behind the reuseCollectedDataRuleErrors feature toggle, which is on in bleeding edge only. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
SanderMuller
force-pushed
the
cache-collected-data-rule-errors
branch
from
October 26, 2026 14:43
b6b5518 to
c96f229
Compare
Contributor
Author
|
Thanks, I did 1 and 2:
One gap is left: values that a class reflection extension tracks with For 3, I will open issues on larastan, dead-code-detector and the other extensions with collectors after 2.3.3 is out. |
Member
Yeah, these should all work |
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, and it is not behind the toggle.
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. Such a rule declares that data with theDependencyTrackermethods, for exampletrackDirectoryDependency(). The values are stored with its errors, and the rule runs again when one of them changes. Before this PR, these methods did nothing in a rule onCollectedDataNode.The reuse is behind the
reuseCollectedDataRuleErrorsfeature toggle, which is on in bleeding edge only. Without it, every rule runs on every run, as before.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