Skip to content

Pack private cache lines, add branch hints, and force-inline hot methods - #72

Merged
rigtorp merged 4 commits into
masterfrom
perf-cache-line-layout
Nov 17, 2026
Merged

rigtorp merged 4 commits into
masterfrom
perf-cache-line-layout

Conversation

@rigtorp

@rigtorp rigtorp commented Nov 17, 2026

Copy link
Copy Markdown
Owner

Optimizes rigtorp::SPSCQueue cache-line layout and codegen in include/rigtorp/SPSCQueue.h:

  • Isolates shared writeIdx_ and readIdx_ on separate kFalseSharingRange-aligned lines from private writer_ / reader_ state.
  • Packs private writeIdx, readIdx, readIdxCache, writeIdxCache, and local copies of slots / capacity (plus allocator in writer_) onto the owning thread's private cache line, avoiding cold-cache header fetches and Shared-state contention on empty/full polling.
  • Adds [[unlikely]] branch hints on wrap-around and cache-miss reloads.
  • Adds RIGTORP_SPSCQUEUE_INLINE ([[gnu::always_inline]] inline / __forceinline) to hot producer/consumer methods so large translation units do not outline them.

@rigtorp
rigtorp force-pushed the perf-cache-line-layout branch from 643a3ac to f646e89 Compare November 17, 2026 05:38
@rigtorp
rigtorp merged commit f171d39 into master Nov 17, 2026
10 checks passed
@rigtorp
rigtorp deleted the perf-cache-line-layout branch November 17, 2026 05:44
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.

1 participant