Skip to content

[Caching] Keep cache on rule removal and skip addition - #8397

Merged
TomasVotruba merged 3 commits into
mainfrom
tv-cache-invalidation-granular
Aug 29, 2026
Merged

[Caching] Keep cache on rule removal and skip addition#8397
TomasVotruba merged 3 commits into
mainfrom
tv-cache-invalidation-granular

Conversation

@TomasVotruba

Copy link
Copy Markdown
Member

Today any change to any config parameter drops the whole cache, because FileHashComputer hashes every parameter through SimpleParameterProvider::hash(). So removing a rule from withRules(), adding a withSkip() item, or even flipping --parallel forces a full re-run.

This compares config changes by direction instead of a flat hash:

  • removing a rule/set, or adding a skip -> strictly less work -> cache kept
  • adding a rule/set, or removing a skip -> more work possible -> cache dropped
  • output-affecting parameters (php version, import names, indent, ...) -> any change still drops the cache
  • runtime/reporting parameters (parallel, memory limit, deprecation notices, unused-skip reporting) -> excluded, never invalidate

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.
  • ChangedFilesDetector stores a small snapshot (strict hash + hashed rule/set/skip lists) and compares it directionally on the next run.
  • A legacy string cache value from an older version triggers a single safe reset.

Note

A pre-existing gap, not changed here: a configured rule value change via withConfiguredRule() is stored on RectorConfig, not in the parameter bag, so it already does not invalidate the cache. Can be a follow-up if worth closing.

TomasVotruba and others added 3 commits August 29, 2026 00:55
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
@TomasVotruba
TomasVotruba merged commit 90f4663 into main Aug 29, 2026
44 checks passed
@TomasVotruba
TomasVotruba deleted the tv-cache-invalidation-granular branch August 29, 2026 07:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

2 participants