-
Notifications
You must be signed in to change notification settings - Fork 38.7k
Do not fully sort all nodes for addr relay #8690
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
|
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). |
|
@sipa is it worth benchmarking this (since you mentioned benchmarking)? |
|
@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. |
src/main.cpp
Outdated
There was a problem hiding this comment.
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?
076d877 to
12df591
Compare
|
Rebased and addressed @gmaxwell's nit. |
|
utACK. |
As we only need 1 or 2, explicitly keep track of the best ones.
|
Rebased after #8914. |
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 |
a33b169 Do not fully sort all nodes for addr relay (Pieter Wuille)
a33b169 Do not fully sort all nodes for addr relay (Pieter Wuille)
a33b169 Do not fully sort all nodes for addr relay (Pieter Wuille)
a33b169 Do not fully sort all nodes for addr relay (Pieter Wuille)
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.