Improve addrman Select() performance when buckets are nearly empty #6530

pull sipa wants to merge 1 commits into bitcoin:master from sipa:fastselect changing 1 files +8 −4
  1. sipa commented at 5:49 PM on August 6, 2015: member

    Earlier, when there are only a few entries in the addrman tables, Select() could spin for long periods of time (~200ms), resulting in high CPU usage (up to 40% here). This reduces it to around 0.3ms (0.5% CPU).

  2. sipa force-pushed on Aug 6, 2015
  3. sipa force-pushed on Aug 6, 2015
  4. dgenr8 commented at 3:38 AM on August 7, 2015: contributor

    utACK

  5. laanwj added the label P2P on Aug 7, 2015
  6. TheBlueMatt commented at 1:37 PM on August 8, 2015: member

    utACK

  7. gmaxwell commented at 10:05 PM on August 22, 2015: contributor

    ACK

  8. Improve addrman Select() performance when buckets are nearly empty c33c11ebac
  9. in src/addrman.cpp:None in 9ddf0fdce3 outdated
     340 | @@ -341,8 +341,11 @@ CAddrInfo CAddrMan::Select_()
     341 |          while (1) {
     342 |              int nKBucket = GetRandInt(ADDRMAN_TRIED_BUCKET_COUNT);
     343 |              int nKBucketPos = GetRandInt(ADDRMAN_BUCKET_SIZE);
     344 | -            if (vvTried[nKBucket][nKBucketPos] == -1)
     345 | -                continue;
     346 | +            while (1) {
    


    laanwj commented at 12:05 PM on August 24, 2015:

    Equivalent but maybe slightly more readable:

    while(vvTried[nKBucket][nKBucketPos] == -1) {
        nKBucket = (nKBucket + insecure_rand()) % ADDRMAN_TRIED_BUCKET_COUNT;
        nKBucketPos = (nKBucketPos + insecure_rand()) % ADDRMAN_BUCKET_SIZE;
    }
    

    sipa commented at 12:01 AM on August 26, 2015:

    Nit addressed.

  10. sipa force-pushed on Aug 26, 2015
  11. dcousens commented at 2:07 AM on August 26, 2015: contributor

    utACK

  12. laanwj merged this on Aug 26, 2015
  13. laanwj closed this on Aug 26, 2015

  14. laanwj referenced this in commit ea19c2bc3f on Aug 26, 2015
  15. DrahtBot locked this on Sep 8, 2021

github-metadata-mirror

This is a metadata mirror of the GitHub repository bitcoin/bitcoin. This site is not affiliated with GitHub. Content is generated from a GitHub metadata backup.
generated: 2026-04-19 09:15 UTC

This site is hosted by @0xB10C
More mirrored repositories can be found on mirror.b10c.me