Skip to content
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 (backp… (backport #28) #32

Merged
merged 1 commit into from
Apr 30, 2024

Commits on Apr 30, 2024

  1. perf(internal/bits): Significantly speedup bitArray.PickRandom (backp… (

    #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!)
    
    ![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!
    
    ---
    
    - [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)
    czarcas7ic authored and mergify[bot] committed Apr 30, 2024
    Configuration menu
    Copy the full SHA
    a73851c View commit details
    Browse the repository at this point in the history