Repository navigation
Optimization: use write index cache in pop #45
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
Closed
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This optimization leads to 66% more ops/ms
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I benchmarked this in optimized Release builds (
-DNDEBUG) and could not reproduce a throughput improvement on this machine.The comparison uses the original PR parent,
1053918dbd251fbff69b24ef27fa5d51c29ec2af, with four variants:writeIdx_.load(std::memory_order_acquire)in thepop()assertion withwriteIdxCache_; no other changes.if (readIdx == writeIdxCache_)refresh highlighted in this thread; retain the original constructor and increment/compare wraparound.552d2eb8453468474e84d304ceffe8c756a3d84d, including the constructor changes and% capacity_wraparound.Results are medians of 16 measured rounds, with variant order randomized within each round after warmup:
Test details:
-std=c++17 -O3 -march=native -DNDEBUG -pthread. Assertions are disabled in every result above.rigtorp::SPSCQueue<uint64_t>, rather than the repository's multi-queue benchmark executable. Each receive waits for a non-nullfront(), reads the value, then callspop(). The receive helper is forced inline sofront()andpop()stay together in the consumer loop.The cached-assertion-only and original Release executables have byte-identical
.textsections, as expected when the assertion is compiled out. Their measurement differences should therefore be treated as run-to-run variation.The conditional refresh measured about 6.5% lower large-capacity throughput than the original here. The large-capacity throughput interquartile ranges were 776.5–837.8 Mops/s for the original and 734.5–771.2 Mops/s for the refresh variant. The refresh changes generated code despite being redundant for a valid successful-
front()/pop()sequence.The full PR measured about 53.4% lower large-capacity throughput. Disassembly shows integer divide instructions in that variant, while the three variants retaining the original wraparound have none; this is consistent with a cost from the modulo changes, although this comparison does not isolate modulo from every other full-PR change.
These are local measurements with frequency boost enabled, without fixed-frequency or OS CPU isolation. They do not establish a universal percentage, but they provide no evidence of a Release performance improvement from the proposed refresh on this machine.