Skip to content

Avoid reallocation on the first insertion into small maps - #5

Merged
rigtorp merged 1 commit into
masterfrom
fix/minimum-bucket-count
Oct 4, 2026
Merged

rigtorp merged 1 commit into
masterfrom
fix/minimum-bucket-count

Conversation

@rigtorp

@rigtorp rigtorp commented Oct 4, 2026 •

Copy link
Copy Markdown
Owner

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 fmix64 integer 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.

@rigtorp
rigtorp force-pushed the fix/minimum-bucket-count branch from a704600 to 10a7ba5 Compare October 4, 2026 23:12
@rigtorp
rigtorp merged commit 5688f23 into master Oct 4, 2026
3 checks passed
@rigtorp
rigtorp deleted the fix/minimum-bucket-count branch October 4, 2026 23:13
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.

Constructor can start selecting the bucketlist size at 2 instead of 1

1 participant