paritytech/litep2p

Optimize `RoutingTable::closest_iter()`

Closed this issue · 0 comments

RoutingTable::closest_iter() indexes into the correct bucket and if that bucket doesn't have limit many peers, it collects peers from all buckets, sorts them and then takes as many peers as it takes to fill the request for limit many peers. This is extremely dumb. rust-libp2p has a ClosestIter iterator which visits the buckets in an optimal order and doesn't require sorting the entire routing table when trying to fill the request for limit many closest peers. Similar approach should be taken with litep2p's Kademlia implementation.