perf(communication): Avoid shared queue-header reads and add opt-in idle backoff - #180
Merged
Merged
Conversation
gd-0
requested changes
Sep 18, 2026
louisponet
reviewed
Sep 18, 2026
louisponet
left a comment
Contributor
There was a problem hiding this comment.
Would like to know whether it's actually the self.mask and not just the div. Can you compare your benches with only the div change (mainly for my curiosity)
Bronek
force-pushed
the
bronek/optimize_MPMC_queue
branch
from
September 21, 2026 09:26
adb9817 to
3cead80
Compare
gd-0
reviewed
Sep 21, 2026
Use the consumer's cached ring mask and a power-of-two shift when updating its position and expected seqlock epoch. This avoids reading the header cache line shared with the producers' count and removes the division. Retain cursor atomics and make the old epoch helper test-only. Cover broadcast epoch stamps, wraparound and recovery, plus collaborative claims with changing consumer polling order. Negative controls reject an incorrect epoch and duplicate claims. Workspace tests with all features, check, Clippy, formatting and dependency checks pass. Nine paired runs on isolated Ryzen 9 9950X cores 12-15 measured 20-35% less time per message for 2/3 producers and 8/64-byte payloads. The one-producer 64-byte case regressed 33.7%; the improvement is workload-dependent. Assisted-by: Codex:GPT-6
Add TileConfig::with_idle_backoff with a zero-pause default. Spin only when the whole iteration recorded no work, after the stop check; eligible parking takes precedence. Queue reads remain nonblocking. A drain-to-empty benchmark with two MPMC producers measured 27.55 to 25.79 ns/message for 64-byte payloads at 16 pauses, and 36.25 to 33.66 for 256-byte payloads. Sparse 64-byte SPMC p99 rose from 100 to 280 ns, so backoff is opt-in and is not a general fix for queue regressions. Test delivery after idle and scope shutdown with 0, 16 and 32 pauses. Active-iteration suppression and park precedence were reviewed by inspection; the test does not assert scheduler-dependent timings. Assisted-by: Codex:GPT-6
Limit the pause count to 0–255 in TileConfig and its builder method. Assisted-by: Codex:GPT-6
The unpublished-slot race test still called the removed version_at helper. Subscribe a probe before reserving the slot and verify that it reports Empty. Assisted-by: Codex:GPT-6
Remove the idle-backoff configuration and pause loop, restoring the prior parking flow. Keep PR #180 focused on the cached-mask queue optimization; backoff can be considered in a separate PR. Validated flux tests with default and all features, workspace all-feature compilation, formatting, and Clippy with warnings denied. Assisted-by: Codex:GPT-6
Bronek
force-pushed
the
bronek/optimize_MPMC_queue
branch
from
September 22, 2026 12:58
73c0ea6 to
4bb5a7f
Compare
gd-0
approved these changes
Sep 22, 2026
Contributor
Author
|
To future readers - there is no idle backoff in this PR. It was removed in the last commit but I forgot to update the topic line, and the merge commit says "idle backoff" when in fact it is not there. Sorry everyone 😭 |
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.
Derive consumer epochs from the cached ring mask, removing a shared-header load and integer division in
ConsumerBare. This applies to both MPMC and SPMC.The header mask shares a cache line with the producer counter. A consumer reading the mask can cause that line to be shared; the producer’s next counter update must obtain exclusive ownership and invalidate the consumer’s copy. The read itself does not invalidate the producer’s copy. Using the cached mask avoids this source of false sharing. The power-of-two ring length also allows a shift instead of division. These measurements evaluate both changes together; they do not attribute a percentage of the gain to either one.
There is no idle backoff in this PR despite to what the subject line says - it was removed in the last commit