Skip to content

Update uthash.h to permit preallocation - #274

Open
sbergercnmc wants to merge 1 commit into
troydhanson:masterfrom
sbergercnmc:patch-1
Open

Update uthash.h to permit preallocation#274
sbergercnmc wants to merge 1 commit into
troydhanson:masterfrom
sbergercnmc:patch-1

Conversation

@sbergercnmc

Copy link
Copy Markdown

Placed HASH_INITIAL_NUM_BUCKETS and HASH_INITIAL_NUM_BUCKETS_LOG2 into a #ifndef block so as to permit these values to be optionally defined in other code before inclusion of uthash.h and thus permit preallocation of hashtable when a lot of keys are expected to be added.

Placed HASH_INITIAL_NUM_BUCKETS and HASH_INITIAL_NUM_BUCKETS_LOG2 into a #ifndef block so as to permit these values to be optionally defined in other code before inclusion of uthash.h and thus permit preallocation of hashtable when a lot of keys are expected to be added.
@Quuxplusone

Copy link
Copy Markdown
Collaborator

Seems plausible at first glance. Obvious questions:

  • Have you used this in production? Does it help?
  • Surely HASH_BKT_CAPACITY_THRESH should get the same treatment?
  • Needs some test coverage.

@sbergercnmc

Copy link
Copy Markdown
Author

Doing this for my use case, where I am loading over 300,000,000 keys (uint64_t), my program's loading time goes from 178 seconds to 93 seconds... Agreed that same idea can be applied to HASH_BKT_CAPACITY_THRESH, but I haven't needed this for my use case.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants