-
Notifications
You must be signed in to change notification settings - Fork 478
fix: dialling duplicated addresses #1489
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
@@ -259,6 +259,8 @@ export class DefaultDialer implements Startable, Dialer { | |||
async (source) => await all(source) | |||
) | |||
|
|||
addrs = [...new Set(addrs)] |
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.
No concerns for performance and unnecessary allocation of tons of memory for just selecting a list of addresses?
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.
Don't think performance or memory will be issue here as we are mostly talking about <10addresses
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.
It's not that it's an issue, it that it is unnecessary to tackle this problem this way. This entire function contains multiple un-explicable design choices with the common theme of zero regard for performance in exchange for no clear benefit. A non-piped version would be even easier to read and mantain, and would not require to loop again in the Set iteration to drop duplicates
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.
As an extreme example: this solution below is correct, and won't affect performance in libp2p overall. But we should never accept it regardless
addrs = [...new Set(addrs)] | |
addrs = [...new Set([...new Set([...new Set(addrs)])])] |
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 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.
The decision here was to fix the issue and tackle rest in separate issue like #1490
As for duplicate removal, I agree, using includes
or indexOf
here would be better but for larger arrays [...new Set(addrs)]
(> ~100elements) is a lot faster^^
resolves #1409