-
Notifications
You must be signed in to change notification settings - Fork 645
perf(internal/bits): Significantly speedup bitArray.PickRandom #2841
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
perf(internal/bits): Significantly speedup bitArray.PickRandom #2841
Conversation
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.
Thanks @ValarDragon ❤️
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.
Great work.
Left some comments regarding the documentation of the introduced methods.
internal/bits/bit_array.go
Outdated
trueIndices := make([]int, 0, bA.Bits) | ||
curBit := 0 | ||
// getNthTrueIndex returns the index of the nth true bit in the bit array. | ||
// If there is no such value, it returns 0. It is required that the caller |
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.
Returns -1, doesn't it?
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.
Whoops yes, thank you!
internal/bits/bit_array.go
Outdated
curBit := 0 | ||
// getNthTrueIndex returns the index of the nth true bit in the bit array. | ||
// If there is no such value, it returns 0. It is required that the caller | ||
// ensures that n is less than or equal to the number of true bits in the bit array. |
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 is requirement is not really a requirement, right? The code support this case, but returns -1.
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.
True!
I didn't add to the review, but I was thinking the following. This is only a suggestion. We implement Assuming that we know the maximum number of bits stored, lets say My point here is that we probably can implement |
@@ -301,3 +387,15 @@ func TestUnmarshalJSONDoesntCrashOnZeroBits(t *testing.T) { | |||
require.NoError(t, err) | |||
require.Equal(t, ic.BitArray, &BitArray{Bits: 0, Elems: nil}) | |||
} 8000 | |||
|
|||
func BenchmarkPickRandomBitArray(b *testing.B) { |
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 wonder if adding some contention to this benchmark would affect the results. I think the results are better with this PR, but maybe this is something to explore. By contention, I mean, another thread changing the bit set while we are retrieving random indexes.
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.
Where this is used, these mutexes are truly useless. We are operating on a clone that is only owned in a single threaded function. Was going to make an issue to make a new bit array version that gets rid of the mutexes
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 would be ideal. In particular because I assume that the methods using this are already synchronized.
For instance, consensus state, peer consensus state should be synchronized.
I thought about the second method, but getting perfect distribution will require rejection sampling which is potentially much slower. (Doing i%n biases the random distribution which is more scary for edge case slowdowns imo.) Rejection sampling seems like unneeded edge case slowdowns right now. Targeting a single pass seems like large overkill when in the systemic view or what's going on with the bit arrays, we're very wasteful at the moment. (Two Extra full clones in the relevant vote sampling code. We clone the bit array from votes, then do a sub call that allocates another bit array, and everything here is single threaded but does mutexes. The mutex call's Cas operation is likely slower than the first pass of this codes ~16 bitwise math ops per word) |
I didn't fully get this rejection sampling part, but I was wondering whether |
Also agree that removing locks is much more relevant for performance than saving a few loops. |
We can have this as a private field:
I should probably create an issue from this. |
Your totally right, that would work! I expect that the difference in performance for the PickRandom call won't be that high (I think were already fast enough here / remaining time is coming from the Mutex), but agreed that seems like a better solution! |
<!-- Please add a reference to the issue that this PR addresses and indicate which files are most critical to review. If it fully addresses a particular issue, please include "Closes #XXX" (where "XXX" is the issue number). If this PR is non-trivial/large/complex, please ensure that you have either created an issue that the team's had a chance to respond to, or had some discussion with the team prior to submitting substantial pull requests. The team can be reached via GitHub Discussions or the Cosmos Network Discord server in the #cometbft channel. GitHub Discussions is preferred over Discord as it allows us to keep track of conversations topically. https://github.com/cometbft/cometbft/discussions If the work in this PR is not aligned with the team's current priorities, please be advised that it may take some time before it is merged - especially if it has not yet been discussed with the team. See the project board for the team's current priorities: https://github.com/orgs/cometbft/projects/1 --> This PR significantly speeds up bitArray.PickRandom which is used in VoteGossip and BlockPart gossip. We saw for a query serving full node, over an hour, this was a very large amount of RAM allocations. (75GB of RAM!)  This PR drops it down to 0 allocations, and makes the routine 10x faster on my machine. OLD: ``` BenchmarkPickRandomBitArray-12 1545199 846.1 ns/op 1280 B/op 1 allocs/op ``` NEW: ``` BenchmarkPickRandomBitArray-12 22192857 75.39 ns/op 0 B/op 0 allocs/op ``` I think the new tests I wrote make this more tested than the old code that was here tbh, but pls let me know if theres more tests we'd like to see! --- #### PR checklist - [x] Tests written/updated - [x] Changelog entry added in `.changelog` (we use [unclog](https://github.com/informalsystems/unclog) to manage our changelog) - [x] Updated relevant documentation (`docs/` or `spec/`) and code comments - [x] Title follows the [Conventional Commits](https://www.conventionalcommits.org/en/v1.0.0/) spec (cherry picked from commit b139e13)
<!-- Please add a reference to the issue that this PR addresses and indicate which files are most critical to review. If it fully addresses a particular issue, please include "Closes #XXX" (where "XXX" is the issue number). If this PR is non-trivial/large/complex, please ensure that you have either created an issue that the team's had a chance to respond to, or had some discussion with the team prior to submitting substantial pull requests. The team can be reached via GitHub Discussions or the Cosmos Network Discord server in the #cometbft channel. GitHub Discussions is preferred over Discord as it allows us to keep track of conversations topically. https://github.com/cometbft/cometbft/discussions If the work in this PR is not aligned with the team's current priorities, please be advised that it may take some time before it is merged - especially if it has not yet been discussed with the team. See the project board for the team's current priorities: https://github.com/orgs/cometbft/projects/1 --> This PR significantly speeds up bitArray.PickRandom which is used in VoteGossip and BlockPart gossip. We saw for a query serving full node, over an hour, this was a very large amount of RAM allocations. (75GB of RAM!)  This PR drops it down to 0 allocations, and makes the routine 10x faster on my machine. OLD: ``` BenchmarkPickRandomBitArray-12 1545199 846.1 ns/op 1280 B/op 1 allocs/op ``` NEW: ``` BenchmarkPickRandomBitArray-12 22192857 75.39 ns/op 0 B/op 0 allocs/op ``` I think the new tests I wrote make this more tested than the old code that was here tbh, but pls let me know if theres more tests we'd like to see! --- #### PR checklist - [x] Tests written/updated - [x] Changelog entry added in `.changelog` (we use [unclog](https://github.com/informalsystems/unclog) to manage our changelog) - [x] Updated relevant documentation (`docs/` or `spec/`) and code comments - [x] Title follows the [Conventional Commits](https://www.conventionalcommits.org/en/v1.0.0/) spec (cherry picked from commit b139e13) # Conflicts: # libs/bits/bit_array_test.go
<!-- Please add a reference to the issue that this PR addresses and indicate which files are most critical to review. If it fully addresses a particular issue, please include "Closes #XXX" (where "XXX" is the issue number). If this PR is non-trivial/large/complex, please ensure that you have either created an issue that the team's had a chance to respond to, or had some discussion with the team prior to submitting substantial pull requests. The team can be reached via GitHub Discussions or the Cosmos Network Discord server in the #cometbft channel. GitHub Discussions is preferred over Discord as it allows us to keep track of conversations topically. https://github.com/cometbft/cometbft/discussions If the work in this PR is not aligned with the team's current priorities, please be advised that it may take some time before it is merged - especially if it has not yet been discussed with the team. See the project board for the team's current priorities: https://github.com/orgs/cometbft/projects/1 --> This PR significantly speeds up bitArray.PickRandom which is used in VoteGossip and BlockPart gossip. We saw for a query serving full node, over an hour, this was a very large amount of RAM allocations. (75GB of RAM!)  This PR drops it down to 0 allocations, and makes the routine 10x faster on my machine. OLD: ``` BenchmarkPickRandomBitArray-12 1545199 846.1 ns/op 1280 B/op 1 allocs/op ``` NEW: ``` BenchmarkPickRandomBitArray-12 22192857 75.39 ns/op 0 B/op 0 allocs/op ``` I think the new tests I wrote make this more tested than the old code that was here tbh, but pls let me know if theres more tests we'd like to see! --- #### PR checklist - [x] Tests written/updated - [x] Changelog entry added in `.changelog` (we use [unclog](https://github.com/informalsystems/unclog) to manage our changelog) - [x] Updated relevant documentation (`docs/` or `spec/`) and code comments - [x] Title follows the [Conventional Commits](https://www.conventionalcommits.org/en/v1.0.0/) spec (cherry picked from commit b139e13) # Conflicts: # .changelog/v0.37.5/improvements/2841-speedup-bits-pick-random.md # libs/bits/bit_array_test.go
…ort #2841) (#2887) This PR significantly speeds up bitArray.PickRandom which is used in VoteGossip and BlockPart gossip. We saw for a query serving full node, over an hour, this was a very large amount of RAM allocations. (75GB of RAM!)  This PR drops it down to 0 allocations, and makes the routine 10x faster on my machine. OLD: ``` BenchmarkPickRandomBitArray-12 1545199 846.1 ns/op 1280 B/op 1 allocs/op ``` NEW: ``` BenchmarkPickRandomBitArray-12 22192857 75.39 ns/op 0 B/op 0 allocs/op ``` I think the new tests I wrote make this more tested than the old code that was here tbh, but pls let me know if theres more tests we'd like to see! --- #### PR checklist - [x] Tests written/updated - [x] Changelog entry added in `.changelog` (we use [unclog](https://github.com/informalsystems/unclog) to manage our changelog) - [x] Updated relevant documentation (`docs/` or `spec/`) and code comments - [x] Title follows the [Conventional Commits](https://www.conventionalcommits.org/en/v1.0.0/) spec <hr>This is an automatic backport of pull request #2841 done by [Mergify](https://mergify.com). --------- Co-authored-by: Dev Ojha <ValarDragon@users.noreply.github.com> Co-authored-by: Anton Kaliaev <anton.kalyaev@gmail.com>
Follow-up to #2841 --- #### PR checklist - [x] Tests written/updated - [ ] ~~Changelog entry added in `.changelog` (we use [unclog](https://github.com/informalsystems/unclog) to manage our changelog)~~ - [ ] ~~Updated relevant documentation (`docs/` or `spec/`) and code comments~~ - [x] Title follows the [Conventional Commits](https://www.conventionalcommits.org/en/v1.0.0/) spec
Follow-up to #2841 --- #### PR checklist - [x] Tests written/updated - [ ] ~~Changelog entry added in `.changelog` (we use [unclog](https://github.com/informalsystems/unclog) to manage our changelog)~~ - [ ] ~~Updated relevant documentation (`docs/` or `spec/`) and code comments~~ - [x] Title follows the [Conventional Commits](https://www.conventionalcommits.org/en/v1.0.0/) spec (cherry picked from commit b831f95)
Follow-up to #2841 --- #### PR checklist - [x] Tests written/updated - [ ] ~~Changelog entry added in `.changelog` (we use [unclog](https://github.com/informalsystems/unclog) to manage our changelog)~~ - [ ] ~~Updated relevant documentation (`docs/` or `spec/`) and code comments~~ - [x] Title follows the [Conventional Commits](https://www.conventionalcommits.org/en/v1.0.0/) spec (cherry picked from commit b831f95)
Follow-up to #2841 --- #### PR checklist - [x] Tests written/updated - [ ] ~~Changelog entry added in `.changelog` (we use [unclog](https://github.com/informalsystems/unclog) to manage our changelog)~~ - [ ] ~~Updated relevant documentation (`docs/` or `spec/`) and code comments~~ - [x] Title follows the [Conventional Commits](https://www.conventionalcommits.org/en/v1.0.0/) spec (cherry picked from commit b831f95)
Follow-up to #2841 --- #### PR checklist - [x] Tests written/updated - [ ] ~~Changelog entry added in `.changelog` (we use [unclog](https://github.com/informalsystems/unclog) to manage our changelog)~~ - [ ] ~~Updated relevant documentation (`docs/` or `spec/`) and code comments~~ - [x] Title follows the [Conventional Commits](https://www.conventionalcommits.org/en/v1.0.0/) spec <hr>This is an automatic backport of pull request #2899 done by [Mergify](https://mergify.com). Co-authored-by: Anton Kaliaev <anton.kalyaev@gmail.com>
Follow-up to #2841 --- #### PR checklist - [x] Tests written/updated - [ ] ~~Changelog entry added in `.changelog` (we use [unclog](https://github.com/informalsystems/unclog) to manage our changelog)~~ - [ ] ~~Updated relevant documentation (`docs/` or `spec/`) and code comments~~ - [x] Title follows the [Conventional Commits](https://www.conventionalcommits.org/en/v1.0.0/) spec <hr>This is an automatic backport of pull request #2899 done by [Mergify](https://mergify.com). Co-authored-by: Anton Kaliaev <anton.kalyaev@gmail.com>
Follow-up to #2841 --- #### PR checklist - [x] Tests written/updated - [ ] ~~Changelog entry added in `.changelog` (we use [unclog](https://github.com/informalsystems/unclog) to manage our changelog)~~ - [ ] ~~Updated relevant documentation (`docs/` or `spec/`) and code comments~~ - [x] Title follows the [Conventional Commits](https://www.conventionalcommits.org/en/v1.0.0/) spec <hr>This is an automatic backport of pull request #2899 done by [Mergify](https://mergify.com). Co-authored-by: Anton Kaliaev <anton.kalyaev@gmail.com>
…ort cometbft#2841) (cometbft#2887) This PR significantly speeds up bitArray.PickRandom which is used in VoteGossip and BlockPart gossip. We saw for a query serving full node, over an hour, this was a very large amount of RAM allocations. (75GB of RAM!)  This PR drops it down to 0 allocations, and makes the routine 10x faster on my machine. OLD: ``` BenchmarkPickRandomBitArray-12 1545199 846.1 ns/op 1280 B/op 1 allocs/op ``` NEW: ``` BenchmarkPickRandomBitArray-12 22192857 75.39 ns/op 0 B/op 0 allocs/op ``` I think the new tests I wrote make this more tested than the old code that was here tbh, but pls let me know if theres more tests we'd like to see! --- - [x] Tests written/updated - [x] Changelog entry added in `.changelog` (we use [unclog](https://github.com/informalsystems/unclog) to manage our changelog) - [x] Updated relevant documentation (`docs/` or `spec/`) and code comments - [x] Title follows the [Conventional Commits](https://www.conventionalcommits.org/en/v1.0.0/) spec <hr>This is an automatic backport of pull request cometbft#2841 done by [Mergify](https://mergify.com). --------- Co-authored-by: Dev Ojha <ValarDragon@users.noreply.github.com> Co-authored-by: Anton Kaliaev <anton.kalyaev@gmail.com>
#28) * perf(internal/bits): Significantly speedup bitArray.PickRandom (backport cometbft#2841) (cometbft#2887) This PR significantly speeds up bitArray.PickRandom which is used in VoteGossip and BlockPart gossip. We saw for a query serving full node, over an hour, this was a very large amount of RAM allocations. (75GB of RAM!)  This PR drops it down to 0 allocations, and makes the routine 10x faster on my machine. OLD: ``` BenchmarkPickRandomBitArray-12 1545199 846.1 ns/op 1280 B/op 1 allocs/op ``` NEW: ``` BenchmarkPickRandomBitArray-12 22192857 75.39 ns/op 0 B/op 0 allocs/op ``` I think the new tests I wrote make this more tested than the old code that was here tbh, but pls let me know if theres more tests we'd like to see! --- - [x] Tests written/updated - [x] Changelog entry added in `.changelog` (we use [unclog](https://github.com/informalsystems/unclog) to manage our changelog) - [x] Updated relevant documentation (`docs/` or `spec/`) and code comments - [x] Title follows the [Conventional Commits](https://www.conventionalcommits.org/en/v1.0.0/) spec <hr>This is an automatic backport of pull request cometbft#2841 done by [Mergify](https://mergify.com). --------- Co-authored-by: Dev Ojha <ValarDragon@users.noreply.github.com> Co-authored-by: Anton Kaliaev <anton.kalyaev@gmail.com> * fix failing test * changelog --------- Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com> Co-authored-by: Dev Ojha <ValarDragon@users.noreply.github.com> Co-authored-by: Anton Kaliaev <anton.kalyaev@gmail.com>
#28) * perf(internal/bits): Significantly speedup bitArray.PickRandom (backport cometbft#2841) (cometbft#2887) This PR significantly speeds up bitArray.PickRandom which is used in VoteGossip and BlockPart gossip. We saw for a query serving full node, over an hour, this was a very large amount of RAM allocations. (75GB of RAM!)  This PR drops it down to 0 allocations, and makes the routine 10x faster on my machine. OLD: ``` BenchmarkPickRandomBitArray-12 1545199 846.1 ns/op 1280 B/op 1 allocs/op ``` NEW: ``` BenchmarkPickRandomBitArray-12 22192857 75.39 ns/op 0 B/op 0 allocs/op ``` I think the new tests I wrote make this more tested than the old code that was here tbh, but pls let me know if theres more tests we'd like to see! --- - [x] Tests written/updated - [x] Changelog entry added in `.changelog` (we use [unclog](https://github.com/informalsystems/unclog) to manage our changelog) - [x] Updated relevant documentation (`docs/` or `spec/`) and code comments - [x] Title follows the [Conventional Commits](https://www.conventionalcommits.org/en/v1.0.0/) spec <hr>This is an automatic backport of pull request cometbft#2841 done by [Mergify](https://mergify.com). --------- Co-authored-by: Dev Ojha <ValarDragon@users.noreply.github.com> Co-authored-by: Anton Kaliaev <anton.kalyaev@gmail.com> * fix failing test * changelog --------- Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com> Co-authored-by: Dev Ojha <ValarDragon@users.noreply.github.com> Co-authored-by: Anton Kaliaev <anton.kalyaev@gmail.com> (cherry picked from commit f6abfce)
#28) (#32) * perf(internal/bits): Significantly speedup bitArray.PickRandom (backport cometbft#2841) (cometbft#2887) This PR significantly speeds up bitArray.PickRandom which is used in VoteGossip and BlockPart gossip. We saw for a query serving full node, over an hour, this was a very large amount of RAM allocations. (75GB of RAM!)  This PR drops it down to 0 allocations, and makes the routine 10x faster on my machine. OLD: ``` BenchmarkPickRandomBitArray-12 1545199 846.1 ns/op 1280 B/op 1 allocs/op ``` NEW: ``` BenchmarkPickRandomBitArray-12 22192857 75.39 ns/op 0 B/op 0 allocs/op ``` I think the new tests I wrote make this more tested than the old code that was here tbh, but pls let me know if theres more tests we'd like to see! --- - [x] Tests written/updated - [x] Changelog entry added in `.changelog` (we use [unclog](https://github.com/informalsystems/unclog) to manage our changelog) - [x] Updated relevant documentation (`docs/` or `spec/`) and code comments - [x] Title follows the [Conventional Commits](https://www.conventionalcommits.org/en/v1.0.0/) spec <hr>This is an automatic backport of pull request cometbft#2841 done by [Mergify](https://mergify.com). --------- Co-authored-by: Dev Ojha <ValarDragon@users.noreply.github.com> Co-authored-by: Anton Kaliaev <anton.kalyaev@gmail.com> * fix failing test * changelog --------- Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com> Co-authored-by: Dev Ojha <ValarDragon@users.noreply.github.com> Co-authored-by: Anton Kaliaev <anton.kalyaev@gmail.com> (cherry picked from commit f6abfce) Co-authored-by: Adam Tucker <adam@osmosis.team>
…cometbft#2902) Follow-up to cometbft#2841 --- #### PR checklist - [x] Tests written/updated - [ ] ~~Changelog entry added in `.changelog` (we use [unclog](https://github.com/informalsystems/unclog) to manage our changelog)~~ - [ ] ~~Updated relevant documentation (`docs/` or `spec/`) and code comments~~ - [x] Title follows the [Conventional Commits](https://www.conventionalcommits.org/en/v1.0.0/) spec <hr>This is an automatic backport of pull request cometbft#2 C95D 899 done by [Mergify](https://mergify.com). Co-authored-by: Anton Kaliaev <anton.kalyaev@gmail.com>
…cometbft#2902) (#35) Follow-up to cometbft#2841 --- #### PR checklist - [x] Tests written/updated - [ ] ~~Changelog entry added in `.changelog` (we use [unclog](https://github.com/informalsystems/unclog) to manage our changelog)~~ - [ ] ~~Updated relevant documentation (`docs/` or `spec/`) and code comments~~ - [x] Title follows the [Conventional Commits](https://www.conventionalcommits.org/en/v1.0.0/) spec <hr>This is an automatic backport of pull request cometbft#2899 done by [Mergify](https://mergify.com). Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com> Co-authored-by: Anton Kaliaev <anton.kalyaev@gmail.com>
…cometbft#2902) (#35) Follow-up to cometbft#2841 --- #### PR checklist - [x] Tests written/updated - [ ] ~~Changelog entry added in `.changelog` (we use [unclog](https://github.com/informalsystems/unclog) to manage our changelog)~~ - [ ] ~~Updated relevant documentation (`docs/` or `spec/`) and code comments~~ - [x] Title follows the [Conventional Commits](https://www.conventionalcommits.org/en/v1.0.0/) spec <hr>This is an automatic backport of pull request cometbft#2899 done by [Mergify](https://mergify.com). Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com> Co-authored-by: Anton Kaliaev <anton.kalyaev@gmail.com> (cherry picked from commit 08efc4c)
…cometbft#2902) (#35) Follow-up to cometbft#2841 --- #### PR checklist - [x] Tests written/updated - [ ] ~~Changelog entry added in `.changelog` (we use [unclog](https://github.com/informalsystems/unclog) to manage our changelog)~~ - [ ] ~~Updated relevant documentation (`docs/` or `spec/`) and code comments~~ - [x] Title follows the [Conventional Commits](https://www.conventionalcommits.org/en/v1.0.0/) spec <hr>This is an automatic backport of pull request cometbft#2899 done by [Mergify](https://mergify.com). Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com> Co-authored-by: Anton Kaliaev <anton.kalyaev@gmail.com> (cherry picked from commit 08efc4c)
…cometbft#2902) (#35) (#37) Follow-up to cometbft#2841 --- #### PR checklist - [x] Tests written/updated - [ ] ~~Changelog entry added in `.changelog` (we use [unclog](https://github.com/informalsystems/unclog) to manage our changelog)~~ - [ ] ~~Updated relevant documentation (`docs/` or `spec/`) and code comments~~ - [x] Title follows the [Conventional Commits](https://www.conventionalcommits.org/en/v1.0.0/) spec <hr>This is an automatic backport of pull request cometbft#2899 done by [Mergify](https://mergify.com). Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com> Co-authored-by: Anton Kaliaev <anton.kalyaev@gmail.com> (cherry picked from commit 08efc4c) Co-authored-by: Adam Tucker <adam@osmosis.team>
…cometbft#2902) (#35) (#36) Follow-up to cometbft#2841 --- #### PR checklist - [x] Tests written/updated - [ ] ~~Changelog entry added in `.changelog` (we use [unclog](https://github.com/informalsystems/unclog) to manage our changelog)~~ - [ ] ~~Updated relevant documentation (`docs/` or `spec/`) and code comments~~ - [x] Title follows the [Conventional Commits](https://www.conventionalcommits.org/en/v1.0.0/) spec <hr>This is an automatic backport of pull request cometbft#2899 done by [Mergify](https://mergify.com). Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com> Co-authored-by: Anton Kaliaev <anton.kalyaev@gmail.com> (cherry picked from commit 08efc4c) Co-authored-by: Adam Tucker <adam@osmosis.team>
This PR significantly speeds up bitArray.PickRandom which is used in VoteGossip and BlockPart gossip. We saw for a query serving full node, over an hour, this was a very large amount of RAM allocations. (75GB of RAM!)
This PR drops it down to 0 allocations, and makes the routine 10x faster on my machine.
OLD:
NEW:
I think the new tests I wrote make this more tested than the old code that was here tbh, but pls let me know if theres more tests we'd like to see!
PR checklist
.changelog
(we use unclog to manage our changelog)docs/
orspec/
) and code comments