Skip to content
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

refactor: use HashSet instead of Vec for network links #1739

Closed

Conversation

wyfo
Copy link
Contributor

@wyfo wyfo commented Jan 23, 2025

Links are used a lot for contains operation.

Links are used a lot for `contains` operation.
@wyfo wyfo requested a review from OlivierHecart January 23, 2025 15:49
Copy link

PR missing one of the required labels: {'documentation', 'new feature', 'bug', 'internal', 'enhancement', 'breaking-change', 'dependencies'}

@wyfo wyfo added the internal Changes not included in the changelog label Jan 23, 2025
@@ -1,3 +1,4 @@
use std::collections::HashSet;
Copy link
Member

Choose a reason for hiding this comment

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

Move the use after the header.

@@ -1,3 +1,4 @@
use std::collections::HashSet;
Copy link
Member

Choose a reason for hiding this comment

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

Move the use after the header.

@@ -752,7 +753,7 @@ impl Network {
tracing::trace!("Update edge (link) {} {}", self.graph[self.idx].zid, zid);
self.update_edge(self.idx, idx);
}
self.graph[self.idx].links.push(zid);
self.graph[self.idx].links.insert(zid);
Copy link
Member

Choose a reason for hiding this comment

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

Here there is a semantic change where before the same ZenohId could be present multiple times in the Vec<ZenohIdProto> while now it can be present only once.
Maybe is it worth adding a debug log if insert(zid) returns Some? It would allow to detect if something else is going wrong. What do you think?

@@ -1,3 +1,4 @@
use std::collections::HashSet;
Copy link
Member

Choose a reason for hiding this comment

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

Move use after the header.

@@ -756,7 +757,7 @@ impl Network {
tracing::trace!("Update edge (link) {} {}", self.graph[self.idx].zid, zid);
self.update_edge(self.idx, idx);
}
self.graph[self.idx].links.push(zid);
self.graph[self.idx].links.insert(zid);
Copy link
Member

Choose a reason for hiding this comment

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

Same comment as above on adding a debug log message is insert(zid) returns Some?

@OlivierHecart
Copy link
Contributor

No observed performance improvement.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
internal Changes not included in the changelog
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants