Skip to content

Commit

Permalink
Performance: Use faster hashing algo for cache key generation (#3508)
Browse files Browse the repository at this point in the history
* Use faster hashing algo for cache key generation

* Use 128 bit hashing algo again
  • Loading branch information
keulinho committed Mar 27, 2023
1 parent ae2355d commit 0f0b936
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion rules/Renaming/NodeManipulator/ClassRenamer.php
Original file line number Diff line number Diff line change
Expand Up @@ -452,7 +452,15 @@ private function shouldRemoveUseName(string $last, string $newNameLastName, bool
private function createOldToNewTypes(Node $node, array $oldToNewClasses): array
{
$oldToNewClasses = $this->resolveOldToNewClassCallbacks($node, $oldToNewClasses);
$cacheKey = md5(serialize($oldToNewClasses));

// md4 is faster then md5 https://php.watch/articles/php-hash-benchmark
$hashingAlgorithm = 'md4';
if (\PHP_VERSION_ID >= 80100) {
// if xxh128 is available use it, as it is way faster then md4 https://php.watch/articles/php-hash-benchmark
$hashingAlgorithm = 'xxh128';
}

$cacheKey = \hash($hashingAlgorithm, \serialize($oldToNewClasses));

if (isset($this->oldToNewTypesByCacheKey[$cacheKey])) {
return $this->oldToNewTypesByCacheKey[$cacheKey];
Expand Down

0 comments on commit 0f0b936

Please sign in to comment.