Skip to content

Improve performance of variable resolver#672

Merged
bnoordhuis merged 1 commit intoquickjs-ng:masterfrom
bnoordhuis:fix456-take2
Nov 12, 2024
Merged

Improve performance of variable resolver#672
bnoordhuis merged 1 commit intoquickjs-ng:masterfrom
bnoordhuis:fix456-take2

Conversation

@bnoordhuis
Copy link
Copy Markdown
Contributor

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

@bnoordhuis
Copy link
Copy Markdown
Contributor Author

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
Comment on lines +20524 to +20526
for (p = b; p < (char *)b + n; p++)
h = 33*h + *p;
h += h >> 5;
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Copy Markdown
Contributor

@saghul saghul left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@richarddd
Copy link
Copy Markdown
Contributor

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

@bnoordhuis
Copy link
Copy Markdown
Contributor Author

bnoordhuis commented Nov 12, 2024

we seem to have a few htables around now, do you see an opportunity to DRY some out?

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, shape_hash and get_index_hash have like 5x the number of hash collisions on the (limited) inputs I tested it with.

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.

@bnoordhuis bnoordhuis merged commit 000061f into quickjs-ng:master Nov 12, 2024
@bnoordhuis bnoordhuis deleted the fix456-take2 branch November 12, 2024 20:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

3 participants