-
Notifications
You must be signed in to change notification settings - Fork 143
Switch hashmap implementation to open addressing #301
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
base: master
Are you sure you want to change the base?
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.
I noticed the PR description includes some performance numbers, which is great. However, the commit message only vaguely mentions "slightly higher memory usage" and "significantly improved execution time." Could you include the actual measurements in the commit message as well?
4d3545d
to
c948a44
Compare
bf383cf
to
f513a1c
Compare
f513a1c
to
b1b3230
Compare
Previously, the chaining implementation incurred pointer chasing and per-node allocations, leading to poor cache locality and longer chains under collisions. Open addressing uses a single contiguous array and removes per-node allocations. We cap the load factor at 50% to keep probe lengths short and reduce clustering. This change trades ~320 kB of memory for ~30 ms faster execution, primarily due to better cache locality. Notice that current implementation lacks delete state as there is no in-place delete use case.
b1b3230
to
f4943ae
Compare
Just out of curiosity, how did you test the correctness of this patch? |
I validated this patch with shecc's test suite ( |
Previously, the chaining implementation incurred pointer chasing and per-node allocations, leading to poor cache locality and longer chains under collisions.
Open addressing uses a single contiguous array and removes per-node allocations. We cap the load factor at 50% to keep probe lengths short and reduce clustering.
This change trades ~320 kB of memory for ~30 ms faster execution, primarily due to better cache locality.
Validated with shecc’s test suite (
make check
).Notice that current implementation lacks delete state as there is no in-place delete use case.
Performance analysis for out/shecc src/main.c
Using
/usr/bin/time -v
and uftrace to benchmark memory usage and execution time.Chaining
/usr/bin/time -v
uftrace
Open Addressing
/usr/bin/time -v
uftrace
Summary by cubic
Switch hashmap from separate chaining to open addressing with linear probing, rehashing at 50% load. This improves cache locality and delivers a small, consistent speedup with similar memory usage.
Refactors
Performance