-
Notifications
You must be signed in to change notification settings - Fork 132
perf(l1): optimize get closest nodes #4838
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
Lines of code reportTotal lines added: Detailed view |
…ap with fast lookup and slow iteration
4700ac1 to
caff76b
Compare
Benchmark Block Execution Results Comparison Against Main
|
|
|
||
| for contact_to_discard_id in disposable_contacts { | ||
| self.contacts.remove(&contact_to_discard_id); | ||
| self.contacts.swap_remove(&contact_to_discard_id); |
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.
Does indexmap have something like Vec::retain ? We could replace this loop with that
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.
i would prefer to look at this in another pr/change
ElFantasma
left a comment
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.
Whoa, nice improvement!
According to profiling, the get_closest_nodes is mainly bound by iterating the contacts btreemap.
Replaced the contacts btreemap with indexmap. Also replaced the peers one since it also beneffits from this.
Comparing profiling info, it goes from 31% of time taken to 3%.
Hoodi synced in 7mins 32seconds more or less
Reasoning:
Btreemap has fast lookup and slow iteration.
indexmap has fastish lookup and vec-like iteration
introduces a new dep: https://crates.io/crates/indexmap ( 662,138,228 downloads )