-
-
Notifications
You must be signed in to change notification settings - Fork 18.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Clean up Hash Functions #62176
Clean up Hash Functions #62176
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good to me:)
I wonder if we could use murmur3 for string hashing too? Based on this actually pretty good stackexchange answer it should perform better than DBJ2, other benchmarks show similar results (though I am not sure how it behaves with short strings). During my experiments with different hash functions I tried to do that, but the engine crashed since it somehow broke ClassDB.
StringName makes an assumption that all encodings of a string will result with the same hash, e.g. with a It's also worth noting that Murmur3A is slower than the DJB2 algorithm for strings under ~16 characters or so. I've been doing my own tests with hashes and have yet to find a good solution that performs better than the current version. I'm currently of the impression that just using a higher-quality minimal algorithm such as FNV-1a everywhere will end up being more performant than trying to use a heavier algorithm in certain circumstances due to being easier to inline. |
@lmurray @Geometror To be honest I think for strings DJB2 does the job. The reason I moved most stuff to murmur3 is to improve the distribution in robin hood hash tables (which are super fast, but require in exchange much better hashing than what we had, or else the empty spaces get a poor distribution in big tables. This happens specially when using sequential elements, which DJB2 kind of sucks for). But for strings it should be fine, I don't see distribution being a problem in that scenario, so I doubt it makes much sense to change. |
d209722
to
31d7a64
Compare
Clean up and do fixes to hash functions and newly introduced murmur3 hashes in godotengine#61934 * Clean up usage of murmur3 * Fixed usages of binary murmur3 on floats (this is invalid) * Changed DJB2 to use xor (which seems to be better)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should be good to go, we can always change these if we find something which has a noticeable performance benefit over the combination of murmur3 and dbj2.
Thanks! |
Side note: are the new hash() functions exposed to the scripting? I need to hash a Vector3... |
Clean up and do fixes to hash functions and newly introduced murmur3 hashes in #61934