-
-
Notifications
You must be signed in to change notification settings - Fork 560
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
Use FNV hash for Key #1736
Use FNV hash for Key #1736
Conversation
lahma
commented
Jan 12, 2024
- https://en.wikipedia.org/wiki/Fowler%E2%80%93Noll%E2%80%93Vo_hash_function
@@ -14,7 +15,7 @@ namespace Jint | |||
private Key(string name) | |||
{ | |||
Name = name; | |||
HashCode = StringComparer.Ordinal.GetHashCode(name); | |||
HashCode = Hash.GetFNVHashCode(name); |
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 it be lazy or is any Key always checked at least once for equality?
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.
The keys are basically always used against dictionaries, we are trying to find identifiers in context (variables, object fields), we climb up the environment util root (global) and each time pre-calculated hash is being used.
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.
A stupid idea you will debunk for sure: Assuming most keys are smallish, can't we use an optimization by using the raw memory value of the strings < 8 chars (64bits -> int
) as the hashcode? And then fallback above 8 chars? This way for <8 chars we just need to compare the hashes too, and the computation could be faster (TBD).
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.
Not a stupid idea for sure, makes sense but I'm not an entropy expert (how that would affect collisions).
I also played with the idea of having length < 4 directly interned and then reference equals would suffice in Key context.
I hope to create a new baseline to improve upon, but feels that perf runs can be quite unreliable - results vary a lot...
Jint.Benchmark.DromaeoBenchmark
|
|