Skip to content

Conversation

mergify[bot]
Copy link
Contributor

@mergify mergify bot commented Feb 12, 2024

This is an automatic backport of pull request #2246 done by Mergify.


Mergify commands and options

More conditions and actions can be found in the documentation.

You can also trigger Mergify actions by commenting on this pull request:

  • @Mergifyio refresh will re-evaluate the rules
  • @Mergifyio rebase will rebase this PR on its base branch
  • @Mergifyio update will merge the base branch into this PR
  • @Mergifyio backport <destination> will backport this PR on <destination> branch

Additionally, on Mergify dashboard you can:

  • look at your merge queues
  • generate the Mergify configuration with the config editor.

Finally, you can contact us on https://mergify.com

…rformance (#2246)

Original PR: #2159

## Breaking changes

- `[p2p]` Rename `IPeerSet#List` to `Copy`, add `Random`, `ForEach`
methods.
   Rename `PeerSet#List` to `Copy`, add `Random`, `ForEach` methods.

Fixes #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 #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 #2157

---------

Co-authored-by: Emmanuel T Odeke <emmanuel@orijtech.com>
Co-authored-by: Sergio Mena <sergio@informal.systems>
(cherry picked from commit e1ee71c)
@mergify mergify bot requested review from a team as code owners February 12, 2024 12:24
@mergify mergify bot requested a review from a team February 12, 2024 12:24
@melekes melekes merged commit 07a4b69 into v1.x Feb 12, 2024
@melekes melekes deleted the mergify/bp/v1.x/pr-2246 branch February 12, 2024 12:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant