avalanchego icon indicating copy to clipboard operation
avalanchego copied to clipboard

network/p2p/gossip: refactor Set.Add to accept multiple elements

Open lebdron opened this issue 1 year ago • 1 comments

Allows potential optimized implementations for adding multiple elements to sets of Gossipables.

Why this should be merged

Coreth currently has to pass every received transaction to the mempool in a separate Add call, requiring exclusive mutex acquire and release on every call.

https://github.com/ava-labs/coreth/blob/8d22112c7033658eb83b64e8b31d2f9c69676e28/plugin/evm/gossip.go#L192-L194

https://github.com/ava-labs/coreth/blob/8d22112c7033658eb83b64e8b31d2f9c69676e28/core/txpool/legacypool/legacypool.go#L1108-L1110

This interface will allow an optimized implementation to avoid individual Add calls for Coreth.

How this works

How this was tested

lebdron avatar May 03 '24 11:05 lebdron

Do you happen to have any benchmarks/profile that indicate that this is giving us any measurable change in performance? I think unless there is some non-trivial benchmark that shows that this is an improvement we should close this because returning []error introduces unnecessary complexity in the upstream code (ref: diff upstream of p2p) + I think it's a somewhat non-idiomatic way of handling errors in Go.

joshua-kim avatar May 14 '24 13:05 joshua-kim

Closing for the above reason, feel free to re-open.

joshua-kim avatar May 29 '24 15:05 joshua-kim