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

Fix recently added n^2 edge collection #10392

Merged
merged 1 commit into from
Jul 17, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 20 additions & 8 deletions src/rust/engine/graph/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -894,17 +894,29 @@ impl<N: Node> Graph<N> {
/// of a Node. Node cleaning consumes the previous edges for an operation, so we preserve those.
///
/// This is executed as a bulk operation, because individual edge removals take O(n), and bulk
/// edge filtering is both more efficient, and possible to do asynchronously.
/// edge filtering is both more efficient, and possible to do asynchronously. This method also
/// avoids the `retain_edges` method, which as of petgraph `0.4.5` uses individual edge removals
/// under the hood, and is thus not much faster than removing them one by one.
///
/// See https://github.com/petgraph/petgraph/issues/299.
///
pub fn garbage_collect_edges(&self) {
let mut inner = self.inner.lock();
inner.pg.retain_edges(|pg, edge_index| {
let (edge_src_id, _) = pg.edge_endpoints(edge_index).unwrap();
// Retain the edge if it is for either the current or previous run of a Node.
pg[edge_src_id]
.run_token()
.equals_current_or_previous(pg[edge_index].1)
});
inner.pg = inner.pg.filter_map(
|_entry_id, node| Some(node.clone()),
|edge_index, edge_weight| {
let (edge_src_id, _) = inner.pg.edge_endpoints(edge_index).unwrap();
// Retain the edge if it is for either the current or previous run of a Node.
if inner.pg[edge_src_id]
.run_token()
.equals_current_or_previous(edge_weight.1)
{
Some(*edge_weight)
} else {
None
}
},
);
}

///
Expand Down