Repository navigation
Avoid reallocation on the first insertion into small maps - #5
Merged
Merged
Conversation
rigtorp
force-pushed
the
fix/minimum-bucket-count
branch
from
October 4, 2026 23:12
a704600 to
10a7ba5
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Constructing a map with zero or one requested bucket currently allocates one bucket, then reallocates on the first insertion because the maximum load factor is 50%. Start with two buckets so the first element fits without growth. Empty
rehash(0)also retains this minimum; larger requests keep their existing power-of-two rounding.This adds one bucket of storage to empty maps requesting zero or one bucket. Regression tests cover small requests, first insertion, reserve, subsequent growth, value preservation, deletion, clear/rehash/reinsertion, and larger request rounding.
Repair the existing CI build failures: use MurmurHash3's
fmix64integer mixer on ARM and other non-x86-64 targets, retain the CRC hash on x86-64 with an architecture-specific SSE4.2 flag, remove the obsolete Windows 2016 runner, fix benchmark key narrowing and allocator equality, and correct allocator unmap sizing. Require CMake 3.20 for current CMake compatibility and apply the benchmark's C++17 requirement privately. Add a small benchmark smoke test using standard allocation so it runs without configured huge pages.Validation: the regression tests failed with the original constructor. The full test suite passes with GCC 16.2.1 and Clang 22.1.8 using C++14 and strict warnings as errors; the Clang run also passes AddressSanitizer and UndefinedBehaviorSanitizer. The complete GCC CMake build and both CTest checks pass with warnings as errors and ASan/UBSan.
Windows builds the example and regression tests; the POSIX benchmark and its smoke test are built on Linux and macOS. Windows CTest explicitly selects the Debug configuration.
Fixes #3.