Skip to content

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

Merged
merged 1 commit into from
Nov 25, 2022
Merged

Conversation

mpetrunic
Copy link
Member

resolves #1409

@achingbrain achingbrain merged commit 9fd58c8 into master Nov 25, 2022
@achingbrain achingbrain deleted the fix/duplicate-dialer-address branch November 25, 2022 15:14
@@ -259,6 +259,8 @@ export class DefaultDialer implements Startable, Dialer {
async (source) => await all(source)
)

addrs = [...new Set(addrs)]
Copy link
Contributor

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?

Copy link
Member Author

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

Copy link
Contributor

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

Copy link
Contributor

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

Suggested change
addrs = [...new Set(addrs)]
addrs = [...new Set([...new Set([...new Set(addrs)])])]

Copy link
Contributor

Choose a reason for hiding this comment

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

Copy link
Member Author

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^^

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

Duplicated addresses in _createDialTarget
3 participants