Skip to content

Omit redundant buffer padding for aligned element types - #69

Merged
rigtorp merged 1 commit into
masterfrom
fix/aligned-element-padding
Nov 17, 2026
Merged

rigtorp merged 1 commit into
masterfrom
fix/aligned-element-padding

Conversation

@rigtorp

@rigtorp rigtorp commented Nov 17, 2026

Copy link
Copy Markdown
Owner

Summary

Avoid allocating two extra elements when the element alignment already separates the buffer from adjacent allocations. This completes the remaining optimization requested in #30; its redundant trailing-padding cleanup was already applied in 1053918.

alignof(T) >= false-sharing range → zero buffer padding
otherwise                        → keep existing padding at both ends

Add coverage for alignment equal to and greater than the false-sharing range, plus a same-sized type with weaker alignment that must retain padding. Verify exact allocation counts, overflow boundaries through both allocator paths, element alignment, FIFO/full/empty behavior across wraps, and deallocation. Use std::allocator in the tracking allocator so the tests support over-aligned elements.

Fixes #30.

Evidence

  • Before: New boundary tests compiled against the pre-change header fail at CHECK(requested == expected).
    After: Full test suite passes in Debug and Release with GCC 16.2.1, and with AddressSanitizer/UndefinedBehaviorSanitizer.
  • Pinned pre-commit hooks and git diff --check pass.

Merge Danger

Door: two-way

Blast Radius: allocation

Queue storage allocation sizes change for sufficiently aligned element types. Public capacity and synchronization remain unchanged. Custom allocators must honor the element type's alignment requirement.

@rigtorp
rigtorp merged commit 0ca2574 into master Nov 17, 2026
10 checks passed
@rigtorp rigtorp mentioned this pull request Nov 17, 2026
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.

Small things

1 participant