[Caching] Keep cache on rule removal and skip addition - #8397
Merged
Conversation
Compare config changes directionally instead of hashing all parameters: - removing a rule/set or adding a skip keeps the cache (strictly less work) - adding a rule/set or removing a skip still drops it - runtime/reporting parameters (parallel, memory limit, deprecation notices) no longer invalidate the cache Claude-Session: https://claude.ai/code/session_01HegQAw2BRG3G51omvL7QXf
SimpleParameterProvider is a process-wide static; leaving a null bool parameter broke unrelated tests in the same chunk. Capture and restore the touched parameters instead, and assert the strict hash via an array-typed parameter. Claude-Session: https://claude.ai/code/session_01HegQAw2BRG3G51omvL7QXf
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.
Today any change to any config parameter drops the whole cache, because
FileHashComputerhashes every parameter throughSimpleParameterProvider::hash(). So removing a rule fromwithRules(), adding awithSkip()item, or even flipping--parallelforces a full re-run.This compares config changes by direction instead of a flat hash:
Behavior
// rector.php return RectorConfig::configure() ->withRules([ SomeRector::class, - OtherRector::class, ]);Before: full cache dropped, every file re-analysed.
After: cache kept, only changed files re-analysed.
return RectorConfig::configure() ->withSkip([ SomeRector::class, + AnotherRector::class, ]);Before: full cache dropped.
After: cache kept (adding a skip only removes work).
How
SimpleParameterProvider::hashForCacheInvalidation()hashes only output-affecting parameters, leaving out the ignored and directionally compared ones.ChangedFilesDetectorstores a small snapshot (strict hash + hashed rule/set/skip lists) and compares it directionally on the next run.Note
A pre-existing gap, not changed here: a configured rule value change via
withConfiguredRule()is stored onRectorConfig, not in the parameter bag, so it already does not invalidate the cache. Can be a follow-up if worth closing.