-
Notifications
You must be signed in to change notification settings - Fork 139
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?
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.
1 issue found across 2 files
Prompt for AI agents (all 1 issues)
Understand the root cause of the following 1 issues and fix them.
<file name="src/defs.h">
<violation number="1" location="src/defs.h:103">
The new open addressing implementation is fragile because it lacks a 'DELETED' state (tombstone). If an entry is ever removed by setting its state to 0 ('empty'), it will break lookups for all subsequent entries in the same collision chain.</violation>
</file>
Since this is your first cubic review, here's how it works:
- cubic automatically reviews your code and comments on bugs and improvements
- Teach cubic by replying to its comments. cubic learns from your replies and gets better over time
- Ask questions if you need clarification on any suggestion
React with 👍 or 👎 to teach cubic. Mention @cubic-dev-ai
to give feedback, ask questions, or re-run the review.
4d3545d
to
c948a44
Compare
c948a44
to
bf383cf
Compare
Replace chaining with open addressing using Linear Probing. Set load factor to 50% to balance probe length and performance. This change trades ~320 kB of memory for ~30 ms faster execution, primarily due to better cache locality.
bf383cf
to
f513a1c
Compare
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.
Improve git commit messages for the considerations.
This PR replaces chaining with open addressing using linear probing. Set load factor to 50% to balance probe length and performance.
This change trades ~320 kB of memory for ~30 ms faster execution, primarily due to better cache locality.
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