Skip to content

Conversation

@sipa
Copy link
Member

@sipa sipa commented Sep 9, 2016

This is a small optimization, but I have not benchmarked.

Instead of building a hash->node map for each address being relayed, and then picking the top ones, just compute the top 1-2 ones directly.

@sipa sipa changed the title Use a heap to not fully sort all nodes for addr relay Do not fully sort all nodes for addr relay Sep 9, 2016
@sipa
Copy link
Member Author

sipa commented Sep 9, 2016

I had an alternative version that used a heap (which needs less iterator arithmetic), but realized that just explicitly keeping track of the top two is faster (and doesn't need any allocations).

@rebroad
Copy link
Contributor

rebroad commented Sep 15, 2016

@sipa is it worth benchmarking this (since you mentioned benchmarking)?

@sipa
Copy link
Member Author

sipa commented Sep 19, 2016

@rebroad Perhaps, but that will need abstracting this code out so it can be tested in separation from the rest of the p2p message handing.

@laanwj laanwj added the P2P label Sep 22, 2016
src/main.cpp Outdated
Copy link
Contributor

@gmaxwell gmaxwell Sep 22, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There should be an assert here that nRelayNodes is <=2, no?

@sipa sipa force-pushed the heapaddrsort branch 3 times, most recently from 076d877 to 12df591 Compare October 2, 2016 23:57
@sipa
Copy link
Member Author

sipa commented Oct 2, 2016

Rebased and addressed @gmaxwell's nit.

@gmaxwell
Copy link
Contributor

gmaxwell commented Nov 1, 2016

utACK.

As we only need 1 or 2, explicitly keep track of the best ones.
@sipa
Copy link
Member Author

sipa commented Nov 3, 2016

Rebased after #8914.

@laanwj
Copy link
Member

laanwj commented Nov 23, 2016

I had an alternative version that used a heap (which needs less iterator arithmetic), but realized that just explicitly keeping track of the top two is faster (and doesn't need any allocations).

Yes if you just need the top two, a heap is overkill.

Even if this doesn't speed up the critical path this conceptually makes a lot of sense.

utACK a33b169

@laanwj laanwj merged commit a33b169 into bitcoin:master Nov 23, 2016
laanwj added a commit that referenced this pull request Nov 23, 2016
a33b169 Do not fully sort all nodes for addr relay (Pieter Wuille)
codablock pushed a commit to codablock/dash that referenced this pull request Jan 15, 2018
a33b169 Do not fully sort all nodes for addr relay (Pieter Wuille)
andvgal pushed a commit to energicryptocurrency/gen2-energi that referenced this pull request Jan 6, 2019
a33b169 Do not fully sort all nodes for addr relay (Pieter Wuille)
CryptoCentric pushed a commit to absolute-community/absolute that referenced this pull request Feb 24, 2019
a33b169 Do not fully sort all nodes for addr relay (Pieter Wuille)
@bitcoin bitcoin locked as resolved and limited conversation to collaborators Sep 8, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants