Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
perf(internal/bits): Significantly speedup bitArray.PickRandom (backp…
…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!) ![image](https://github.com/cometbft/cometbft/assets/6440154/755918a5-0cef-4e67-a47e-ce8a56aa1cd5) 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>
- Loading branch information
1 parent
4899cd5
commit 983cbaa
Showing
4 changed files
with
149 additions
and
31 deletions.
There are no files selected for viewing
2 changes: 2 additions & 0 deletions
2
.changelog/unreleased/improvements/2841-speedup-bits-pick-random.md
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
- `[internal/bits]` 10x speedup and remove heap overhead of bitArray.PickRandom (used extensively in consensus gossip) | ||
([\#2841](https://github.com/cometbft/cometbft/pull/2841)). |
File renamed without changes.
This file contains 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
This file contains 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