Skip to content
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

Improve bad hash functions #91552

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

Nazarwadim
Copy link
Contributor

Working on #90082. When using the collision checker, I found that hash maps/sets with these hash functions do not work well and create a large number of collisions (max number of collisions is more than 13). So I improved the algorithm for their work. In most cases, I changed the hashing algorithm from djb2 to murmur3. The maximum number of collisions after these changes decreased by 1.5 - 2 times.

@AThousandShips
Copy link
Member

How did you check for these collisions?

@Nazarwadim
Copy link
Contributor Author

Nazarwadim commented May 4, 2024

Used code from this closed pr #72561. Only the check was for the constant 8 and I also used __PRETTY_FUNCTION__ to find the function itself. So, if there were more than 8 collisions, then the console displayed something like this:

WARNING: Excessive collision count (11), is the right hash function being used? Class Name:void HashMap<TKey, TValue, Hasher, Comparator, Allocator>::_insert_with_hash_and_element(uint32_t, HashMapElement<TKey, TValue>*) [with TKey = gd::EdgeKey; TValue = Vector<gd::Edge::Connection>; Hasher = gd::EdgeKey; Comparator = HashMapComparatorDefault<gd::EdgeKey>; Allocator = DefaultTypedAllocator<HashMapElement<gd::EdgeKey, Vector<gd::Edge::Connection> > >; uint32_t = unsigned int]

I used projects such as https://github.com/godotengine/godot-demo-projects and also several of mine.

@fire
Copy link
Member

fire commented May 4, 2024

Since these methods are used in the import pipeline any change to hash functions would need to be an upward upgrade to the import formats.

@Nazarwadim
Copy link
Contributor Author

How is it used? I didn't find any hash calls in the import and io directories related to my changes. Also in most cases, I changed hashers that are used only by hash structures.

@fire
Copy link
Member

fire commented May 4, 2024

@Nazarwadim
Copy link
Contributor Author

@Calinou
Copy link
Member

Calinou commented May 7, 2024

In most cases, I changed the hashing algorithm from djb2 to murmur3

Didn't reduz do the opposite while rewriting HashMap for Godot 4?

Edit: Nevermind, I was thinking about #62176 which doesn't swap the algorithms together; it just cleans them up.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants