|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #79023 very slow hash('crc32b', ...)
Submitted: 2019-12-24 00:07 UTC Modified: 2020-07-20 14:06 UTC
Avg. Score:5.0 ± 0.0
Reproduced:1 of 1 (100.0%)
Same Version:1 (100.0%)
Same OS:1 (100.0%)
From: bugzilla77 at gmail dot com Assigned: cmb (profile)
Status: Closed Package: hash related
PHP Version: 7.4.1 OS: Windows 10
Private report: No CVE-ID: None
 [2019-12-24 00:07 UTC] bugzilla77 at gmail dot com
very slow hash('crc32b', ...)

Test script:





 print($time_a.' sec');
 print($time_b.' sec');
 print($time_c.' sec');

Expected result:
0.34135699272156 sec
<=0.34135699272156 sec
<=0.34135699272156 sec

Actual result:
0.34135699272156 sec
0.77139401435852 sec
0.80676794052124 sec


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2019-12-24 10:30 UTC]
Firstly, crc32($x) doesn't call hash('crc32b', $x), so the
assumption that the latter should be equally fast as the former
(or even faster) is wrong.  Actually, these functions share only
the actual hashing primitives.  Since hash() has to first map the
given string to the desired algorithm, and uses function pointers
subsequently, it is supposed to be somewhat slower.

However, hash() still uses classic ZPP, while crc32() uses the
newer fast ZPP macros, what causes an additional performance

Basically, the same applies to sha1() and md5().
 [2019-12-30 17:31 UTC]
Created to improve hash() performance. With that and a larger tripcount I get:

0.31190896034241 sec
0.48243403434753 sec
0.46064209938049 sec

Getting full parity isn't really possible because a) hash() is dynamic, it needs to lookup the algorithm and dispatch to it and b) hash() returns a string, while crc32() returns an integer.
 [2019-12-31 04:42 UTC] bugreports at gmail dot com
crc32 could be way faster with a native/avx implementation like base64 got in PHP 7.3 looking at the output of mysqld "InnoDB: Using SSE2 crc32 instructions"

currently it's even slower than sha1

and xxhash should be in the official hash-extension

md4:         0.15917
joaat:       0.27944
md5:         0.28036
sha1:        0.38227
crc32:       0.46766
sha3-224:    0.55059
sha3-256:    0.61051
crc32b:      0.64266
crc32c:      0.64455
adler32:     0.70149
sha3-384:    0.75485
sha224:      1.02762
sha256:      1.02943
sha3-512:    1.07797
sha384:      1.13733
sha512/256:  1.143
sha512/224:  1.14454
sha512:      1.14697
whirlpool:   1.76455
 [2020-07-20 14:06 UTC]
-Status: Open +Status: Closed -Assigned To: +Assigned To: cmb
 [2020-07-20 14:06 UTC]
<> has been merged, so
this looks good as bugfix to me.
PHP Copyright © 2001-2021 The PHP Group
All rights reserved.
Last updated: Sun Mar 07 03:01:23 2021 UTC