forked from cometbft/cometbft
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor(p2p)!: Refactor PeerSet to eliminate data races & improve pe…
…rformance (cometbft#2246) Original PR: cometbft#2159 ## Breaking changes - `[p2p]` Rename `IPeerSet#List` to `Copy`, add `Random`, `ForEach` methods. Rename `PeerSet#List` to `Copy`, add `Random`, `ForEach` methods. Fixes cometbft#2158 ## Performance improvement This change makes PeerSet.Remove much more efficient simply by using more idiomatic Go re-slicing to avoid the prior mechanisms of creating fresh peer set lists on just a single remove. While here also added a remedy for a found bug cometbft#2158 due to an abstraction that returns a stale slice to its caller in Switch.OnStop. Benchmark results: ```shell $ benchstat before.txt after.txt name old time/op new time/op delta PeerSetRemoveOne-8 90.5µs ± 4% 95.9µs ±13% ~ (p=0.218 n=10+10) PeerSetRemoveMany-8 1.58ms ± 4% 1.50ms ± 1% -4.98% (p=0.000 n=10+8) name old alloc/op new alloc/op delta PeerSetRemoveOne-8 8.48kB ± 0% 7.92kB ± 0% -6.60% (p=0.000 n=10+10) PeerSetRemoveMany-8 149kB ± 0% 65kB ± 0% -56.44% (p=0.000 n=10+10) name old allocs/op new allocs/op delta PeerSetRemoveOne-8 85.0 ± 0% 73.0 ± 0% -14.12% (p=0.000 n=10+10) PeerSetRemoveMany-8 1.32k ± 0% 1.22k ± 0% -7.51% (p=0.000 n=10+10) ``` which savings become so much more when peers are removed much more frequently for a longer period of time and could mitigate DOS vectors. Fixes cometbft#2157 --------- Co-authored-by: Emmanuel T Odeke <emmanuel@orijtech.com> Co-authored-by: Sergio Mena <sergio@informal.systems>
- Loading branch information
1 parent
460f58c
commit e1ee71c
Showing
18 changed files
with
192 additions
and
143 deletions.
There are no files selected for viewing
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,3 @@ | ||
- `[p2p]` Rename `IPeerSet#List` to `Copy`, add `Random`, `ForEach` methods. | ||
Rename `PeerSet#List` to `Copy`, add `Random`, `ForEach` methods. | ||
([\#2246](https://github.com/cometbft/cometbft/pull/2246)) |
1 change: 1 addition & 0 deletions
1
.changelog/unreleased/improvements/2246-make-peerset-remove-more-efficient.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 @@ | ||
- `[p2p]` make `PeerSet.Remove` more efficient (Author: @odeke-em) [\#2246](https://github.com/cometbft/cometbft/pull/2246) |
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
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
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
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
Oops, something went wrong.