Skip to content

Commit 0f0b936

Browse files
authored
Performance: Use faster hashing algo for cache key generation (#3508)
* Use faster hashing algo for cache key generation * Use 128 bit hashing algo again
1 parent ae2355d commit 0f0b936

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

rules/Renaming/NodeManipulator/ClassRenamer.php

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -452,7 +452,15 @@ private function shouldRemoveUseName(string $last, string $newNameLastName, bool
452452
private function createOldToNewTypes(Node $node, array $oldToNewClasses): array
453453
{
454454
$oldToNewClasses = $this->resolveOldToNewClassCallbacks($node, $oldToNewClasses);
455-
$cacheKey = md5(serialize($oldToNewClasses));
455+
456+
// md4 is faster then md5 https://php.watch/articles/php-hash-benchmark
457+
$hashingAlgorithm = 'md4';
458+
if (\PHP_VERSION_ID >= 80100) {
459+
// if xxh128 is available use it, as it is way faster then md4 https://php.watch/articles/php-hash-benchmark
460+
$hashingAlgorithm = 'xxh128';
461+
}
462+
463+
$cacheKey = \hash($hashingAlgorithm, \serialize($oldToNewClasses));
456464

457465
if (isset($this->oldToNewTypesByCacheKey[$cacheKey])) {
458466
return $this->oldToNewTypesByCacheKey[$cacheKey];

0 commit comments

Comments
 (0)