paritytech / substrate

Substrate: The platform for blockchain innovators
Apache License 2.0
8.39k stars 2.65k forks source link

network: optimize update procedure for listen_addrs and external_addrs #14689

Closed alindima closed 1 year ago

alindima commented 1 year ago

Motivation

Remove the need of updating listen_addresses and external_addresses on every single call to NetworkWorker::next_action.

This is very inefficient, as it involves creating new vectors from hashsets on every call, even if nothing changed in the address set. It turns out to be time consuming when testing in Versi, under a heavy load - about 5-8% of the total polkadot CPU utilisation.

Discussion about motivation here: https://github.com/libp2p/rust-libp2p/discussions/3840#discussioncomment-6575512

Fix

This is a tricky problem to solve, since this data needs to be accessible from a NetworkService instance, which does not have direct access to the Swarm.

Checklist

You can remove the "Checklist" section once all have been checked. Thank you for your contribution!

alindima commented 1 year ago

bot merge

paritytech-processbot[bot] commented 1 year ago

Error: Statuses failed for d646494e512235a04d47f2528ddd6ca228a4a98f