Skip to content

Commit d508860

Browse files
SanderMullerclaude
andcommitted
perf: memoize the parameter hash in DryRunDiffCache
SimpleParameterProvider::hash() serializes the whole parameter bag and contentHash() runs per file, so a warm run paid the serialization once per file (~46ms per 3,200 calls with a 300-entry skip list). Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
1 parent b24354e commit d508860

1 file changed

Lines changed: 12 additions & 5 deletions

File tree

‎src/Caching/DryRunDiffCache.php‎

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,12 +22,17 @@
2222
*
2323
* @see \Rector\Tests\Caching\DryRunDiffCacheTest
2424
*/
25-
final readonly class DryRunDiffCache
25+
final class DryRunDiffCache
2626
{
27+
/**
28+
* memoized: hashing serializes the whole parameter bag, and this runs per file
29+
*/
30+
private ?string $parameterHash = null;
31+
2732
public function __construct(
28-
private Cache $cache,
29-
private FileHasher $fileHasher,
30-
private FileDependencyCollector $fileDependencyCollector,
33+
private readonly Cache $cache,
34+
private readonly FileHasher $fileHasher,
35+
private readonly FileDependencyCollector $fileDependencyCollector,
3136
) {
3237
}
3338

@@ -101,8 +106,10 @@ private function contentHash(File $file, Configuration $configuration): string
101106
{
102107
// --no-diffs changes the produced FileDiff content but is not part of the
103108
// parameter hash, include it so entries do not cross-replay
109+
$this->parameterHash ??= SimpleParameterProvider::hash();
110+
104111
return $this->fileHasher->hash($file->getOriginalFileContent())
105-
. '_' . SimpleParameterProvider::hash()
112+
. '_' . $this->parameterHash
106113
. ($configuration->shouldShowDiffs() ? '' : '_no-diffs');
107114
}
108115
}

0 commit comments

Comments
 (0)