Skip to content

[Caching] Drop MemoryCacheStorage, always use FileCacheStorage - #8354

Merged
TomasVotruba merged 1 commit into
mainfrom
drop-memory-cache-storage
Aug 17, 2026
Merged

[Caching] Drop MemoryCacheStorage, always use FileCacheStorage#8354
TomasVotruba merged 1 commit into
mainfrom
drop-memory-cache-storage

Conversation

@TomasVotruba

Copy link
Copy Markdown
Member

Previously CacheFactory picked MemoryCacheStorage in CI and FileCacheStorage elsewhere. The memory storage was meant to skip "wasted IO" of writing cache files that CI never reads again.

Benchmark on rector's own src/ (491 files, full rule set, --dry-run, PHP 8.4) shows no speed gain from the memory path:

Mode Wall Peak RSS Cache files
FILE cold (empty cache) 23.4 s 301 MB 484 written
FILE warm 3.3 s 178 MB reused
MEMORY (single run) 25–28 s 297 MB 0

Within a single run, MemoryCacheStorage is the same speed as FileCacheStorage cold (both do full analysis; the ~484 cache-file writes cost nothing next to analysis time). It just never persists, so every run stays cold. The only real win comes from the file cache on reruns (~7x faster, 3.3 s vs 23 s).

So the split added a whole storage class and a CiDetector branch for zero measurable benefit. This drops MemoryCacheStorage and always uses FileCacheStorage.

 public function create(): Cache
 {
-    // in CI the workspace is ephemeral and usually starts from scratch,
-    // so a file cache that is never read again is only wasted IO -> use faster in-memory cache
-    if (new CiDetector()->isCiDetected()) {
-        return new Cache(new MemoryCacheStorage());
-    }
-
     $cacheDirectory = SimpleParameterProvider::provideStringParameter(Option::CACHE_DIR);
     ...
     return new Cache(new FileCacheStorage($cacheDirectory, $this->fileSystem));
 }

@TomasVotruba

Copy link
Copy Markdown
Member Author

Ref rectorphp/rector#9855

@TomasVotruba
TomasVotruba merged commit 8eed469 into main Aug 17, 2026
51 checks passed
@TomasVotruba
TomasVotruba deleted the drop-memory-cache-storage branch August 17, 2026 12:00
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.

1 participant