1
0
mirror of https://github.com/danog/psalm.git synced 2024-11-27 04:45:20 +01:00

improve cache hash performance

* do not concatenate with timestamp as this is slow, since $file_contents may be big
* use file contents not file path for cache hash only to ensure it works if file_path not set but file_content is
* improves performance by ~5%
This commit is contained in:
kkmuffme 2022-06-28 15:27:58 +02:00
parent 57239a7c8e
commit 9082eab915
2 changed files with 7 additions and 4 deletions

View File

@ -110,9 +110,9 @@ class ClassLikeStorageCacheProvider
return $cached_value;
}
private function getCacheHash(?string $file_path, ?string $file_contents): string
private function getCacheHash(?string $_unused_file_path, ?string $file_contents): string
{
$data = ($file_path ? $file_contents : '') . $this->modified_timestamps;
$data = $file_contents ? $file_contents : $this->modified_timestamps;
return PHP_VERSION_ID >= 80100 ? hash('xxh128', $data) : hash('md4', $data);
}

View File

@ -117,9 +117,12 @@ class FileStorageCacheProvider
}
}
private function getCacheHash(string $file_path, string $file_contents): string
private function getCacheHash(string $_unused_file_path, string $file_contents): string
{
$data = ($file_path ? $file_contents : '') . $this->modified_timestamps;
// do not concatenate, as $file_contents can be big and performance will be bad
// the timestamp is only needed if we don't have file contents
// as same contents should give same results, independent of when file was modified
$data = $file_contents ? $file_contents : $this->modified_timestamps;
return PHP_VERSION_ID >= 80100 ? hash('xxh128', $data) : hash('md4', $data);
}