Closed
Description
When growing a table, hashbrown will start with a table of size 2 (which can hold 1 element due to load factor) and then double every time the load factor is reached.
Table size | Capacity | Memory usage (sizeof(T) = 4 ) |
Memory usage (sizeof(T) = 8 ) |
Memory usage (sizeof(T) = 16 ) |
---|---|---|---|---|
(empty) | 0 | 0 | 0 | 0 |
2 | 1 | 26 (32) | 34 (40) | 50 (56) |
4 | 3 | 36 (40) | 52 (56) | 84 (88) |
8 | 7 | 56 | 88 | 152 |
16 | 14 | 96 | 160 | 288 |
32 | 28 | 176 | 304 | 560 |
(rounded up to 8 for allocator alignment)
In comparison, the current std HashMap starts off empty but then immediately grows to a table size of 32 (capacity 29) as soon as the first element is added.
We want to try to balance memory usage for small tables with the allocation overhead when growing tables up to their final size.
Metadata
Metadata
Assignees
Labels
No labels