fix Issue 16513 - slow findExistingInstance#6418
Conversation
- use separate branches for the 4 kinds of template arguments
- count lookups and comparisons
|
UplinkCoder
left a comment
There was a problem hiding this comment.
This looks fine at a first glance.
- calc hash for all expressions (matching their equals implementation!) - heavily reduces number of hash collisions and comparisons
- use mixHash from MurmurHash2 for any order sensitive hashes - use ^ instead of + to reduce order insensitive AA elem hashes as it doesn't have the bias towards more significant bits - fixes Issue 16513
|
Not sure if it's relevant to real world template parameters, but the mixing function maps two zero hashes to zero, so if you have N zero hash template parameters it'll have the same hash as M zero hash template parameters. My solution was to use a mixing function like |
- avoids multiplication and returns non-zero hash when combining two zero hash
Nice, thanks for the tip, this reduced the number of collisions even further down to 244. |
My preference would be removing bad defaults[1] and removing that function all together. |
Didn't do this back then b/c we do allow user defined toHash and people love using pointers or non-random ids for hashes. But right, we shouldn't pay for other peoples issues. Then again the mix op is really cheap. |
|
One more thought: it might be profitable to do some additional smearing for pointers to reduce the impact of their alignment. |
That should be covered by the rotate-like |
I was thinking about the small default (size 4?) tables, and how alignment would impact those cases. Anyways, I did a little testing myself [1] and found that the std.algorithm.searching unit test produce a variable amount of collisions (~3600 - 11000.)
None of these changes made collisions consistent, so a little more digging is in order. |
|
Just debugged this, seems to mostly happen because of Lines 6894 to 6923 in 538a895 auto ref is resolved during instantiation, so it seems tricky to distinguish that in advance.Fixing that is somewhat out of scope of this PR. |
|
@MartinNowak go ahead and merge 👍 |
patch collisions while compiling phobos were reduced from ~36K to 376