GetAddr returns all or many randomly selected addresses, it uses vRandom (randomly-ordered vector of all nIds) to get the addresses. However, if a network is specified, we could check the number of entries in vRandom from that network using m_network_counts since it contains the number of entries in addrman per network. This way we could avoid unnecessary searchs in vRandom. So…
This PR improve the performance of addrman’s GetAddr by checking m_network_counts when specifying a network.
AddrManGetAddrByNetwork bench:
master:
0| ns/op | op/s | err% | total | benchmark
1|--------------------:|--------------------:|--------:|----------:|:----------
2| 797,416.00 | 1,254.05 | 0.2% | 0.01 | `AddrManGetAddrByNetwork`
this PR:
0| ns/op | op/s | err% | total | benchmark
1|--------------------:|--------------------:|--------:|----------:|:----------
2| 462,875.00 | 2,160.41 | 5.6% | 0.01 | :wavy_dash: `AddrManGetAddrByNetwork` (Unstable with ~2.2 iters. Increase `minEpochIterations` to e.g. 22)