Improve performance of variable resolver#672
Conversation
|
I'm going to tweak it a little more before I land it, stay tuned. |
Switch to a hash table when the number of variables grows beyond a threshold. Speeds up the test case from the linked issue by about 70%. Fixes: quickjs-ng#456
00d3772 to
129932e
Compare
| for (p = b; p < (char *)b + n; p++) | ||
| h = 33*h + *p; | ||
| h += h >> 5; |
There was a problem hiding this comment.
Switching the hash function resulted in a whopping 15% fewer hash collisions. Pretty big deal.
Catastrophic collisions are still going to be an issue once the table grows to a few million elements but I hope and assume that's never going to happen in the real world. Even that monster from the linked issue has < 20,000 elements.
saghul
left a comment
There was a problem hiding this comment.
Nice! Random question: we seem to have a few htables around now, do you see an opportunity to DRY some out? Not in this PR of course.
This would be great. Maybe even pulling in something external? https://github.com/JacksonAllan/Verstable :D |
Dunno. They're all just different enough from each other that it's not a slam dunk DRY job. I did notice that, compared to perl hash, Swapping the hash function didn't make a measurable difference in my quick testing though, likely because the shape and IC hash tables just don't get that big. |
Switch to a hash table when the number of variables grows beyond a threshold.
Speeds up the test case from the linked issue by about 70%.
Fixes: #456