Skip to content

Improve xmalloc hash - #141

Merged
dag-erling merged 3 commits into
laurikari:masterfrom
dag-erling:des/xmalloc-hash
May 23, 2026
Merged

Improve xmalloc hash#141
dag-erling merged 3 commits into
laurikari:masterfrom
dag-erling:des/xmalloc-hash

Conversation

@dag-erling

Copy link
Copy Markdown
Collaborator

* Rename ptr to addr and change its type to uintptr_t, since we're only
  using it as a unique key and not as a pointer.  This should settle,
  once and for all, the use-after-free issue.

* Rename bytes to size.

* Simplify the search loop in hash_table_del().

* Make stats counters unsigned and static.
Count the number of inserts, hash collisions, and deletions, and report
them along with the other statistics we already report.
* Increase the hash table size from 256 to 8191, which is prime.

* Replace the hash function with Adler-32 modulo the hash table size.

Hash collisions are now down from ~15% to less than 0.1% when running
the test suite.
@dag-erling
dag-erling merged commit a506762 into laurikari:master May 23, 2026
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant