perf: increase min buckets on very small types #615
Merged
+64
−15
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Note: I accidentally closed #524, this is just a continuation of that PR.
Consider
HashSet<u8>
on x86_64 with SSE with various bucket sizes and how many bytes the allocation ends up being:In general, doubling the number of buckets should roughly double the number of bytes used. However, for small bucket sizes for these small
TableLayout
s (4 -> 8, 8 -> 16), it doesn't happen. This is an edge case which happens because of padding of the control bytes and adding theGroup::WIDTH
. Taking the buckets from 4 to 16 (4x) only takes the allocated bytes from 36 to 48 (~1.3x).This platform isn't the only one with edges. Here's aarch64 on an M1 for the same
HashSet<u8>
:Notice doubling from 4 to 8 buckets only lead to 4 more bytes (20 -> 24) instead of roughly doubling.
Generalized,
buckets * table_layout.size
needs to be at least as big astable_layout.ctrl_align
. For the cases I listed above, we'd get these new minimum bucket sizes:This is a niche optimization. However, it also removes possible undefined behavior edge case in resize operations. In addition, it would be a useful property when utilizing over-sized allocations (see #523).