Micro-optimization to the createCacheKey function

Testing showed the in_array function made it overall slower than simply calling MD4. Using a define, I was able to get the overhead down to virtually nothing:
PHP 8.2:
Execution time for MD4: 0.064558029174805 seconds
Execution time for XXH128: 0.015785932540894 seconds
Execution time for Check: 0.0119788646698 seconds

PHP 8.1:
Execution time for MD4: 0.034939050674438 seconds
Execution time for XXH128: 0.0058550834655762 seconds
Execution time for Check: 0.0062451362609863 seconds
This commit is contained in:
Belle Aerni 2023-01-19 01:41:17 -08:00
parent bf3b425c8d
commit ea7f3ac65b
2 changed files with 5 additions and 1 deletions

View file

@ -86,7 +86,7 @@ class AntCache
* If not, use MD4 since it's still quite fast.
* Source: https://php.watch/articles/php-hash-benchmark
*/
if (in_array('xxh128', hash_algos())) {
if (defined('HAS_XXH128')) {
return hash('xxh128', $content . $salt);
} else {
return hash('md4', $content . $salt);

View file

@ -6,3 +6,7 @@ const antPagesList = __DIR__ . DIRECTORY_SEPARATOR . 'Config' . DIRECTORY_SEPA
const antContentPath = __DIR__ . DIRECTORY_SEPARATOR . 'Content';
const antThemePath = __DIR__ . DIRECTORY_SEPARATOR . 'Themes';
const antPluginPath = __DIR__ . DIRECTORY_SEPARATOR . 'Plugins';
if (in_array('xxh128', hash_algos())) {
define('HAS_XXH128', true);
}