Use non-locking operations for nodes count and tbHits #6392
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.
As usual... non-functional speedup.
Failed yellow on Fishtest:
vondele and I chatted on the Discord and agreed that this is probably still a good change even if it doesn't gain on fishtest, given that it gains on at least some systems, and it would be insane for it to regress anywhere. That being said, it might be a good idea to get more benchmarks to understand the impact of this change....
Background/explanation
fetch_addand friends must produce a locking instruction because they guarantee consistency in the presence of multiple writers. Because only one thread ever writes tonodesandtbHits, we may use relaxedloadandstoreto emit regular loads and stores (on both x86-64 and arm64), while avoiding formal 👻 UB 👻 and miscounting nodes.Credit must go to Arseniy Surkov of Reckless (@codedeliveryservice) for uncovering this performance gotcha.
(I'm honestly shocked that this patch works—I guess uncontended atomics are much more expensive than I thought!)
Other data
Benchmark results from vondele's many-core machine:
indicating it scales fine. Interestingly I get only a minuscule speedup on my Zen 5 machine (+0.1%, P>0.99). I can't imagine a case where it'd ever regress though, and fishtest doesn't lie.