Avoid RMWs when polling empty remote queues - #2180
Merged
ericniebler merged 8 commits intoAug 15, 2026
Merged
Conversation
fallintoplace
force-pushed
the
perf/static-thread-pool-empty-remote-poll
branch
from
August 14, 2026 13:23
452a1cc to
7885761
Compare
Collaborator
|
/ok to test 361048d |
Collaborator
|
/ok to test 349c692 |
Collaborator
|
/ok to test 16f3342 |
Collaborator
|
/ok to test 6578d3a |
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.
Summary
Each worker walks every producer shard when checking for remote work. The current empty path performs a compare-exchange from null to null on every shard, taking exclusive ownership of cache lines only to discover that no work is present.
Before sleeping, the worker still does a real dequeue across the remote queues. This keeps the empty check as a speculative optimization while retaining the sleep-boundary safety check.
Benchmark on current HEAD
Equivalent isolated empty remote-queue-list polling on an Apple M1 Pro, optimized build. The isolated numbers were measured before the test and benchmark cleanup commits. The production polling path is unchanged by those cleanup commits. The baseline forces the existing CAS dequeue for every shard; this branch first probes empty() and only dequeues nonempty shards. Values are median nanoseconds per complete list poll.
End-to-end benchmark rerun
Reran
build/examples/example.benchmark.static_thread_poolon an Apple M1 Pro with the Release build.origin/mainat3a836a9716f3342f./build/examples/example.benchmark.static_thread_pool <threads>This is a steady-state scheduling benchmark. It does not measure enqueue-to-start latency or repeated sleep/wake bursts.
Testing
cmake --build build --target test.exec -j2ctest --test-dir build -R 'static_thread_pool' --output-on-failure(14/14 passed)