From c8dfaa5f8d93649acf193d7c89a2a63e5be39690 Mon Sep 17 00:00:00 2001 From: Michael Fazio Date: Tue, 28 Jan 2020 22:22:12 +0800 Subject: [PATCH] Use parallel unstable sort of nodes in Vicinity layer --- Cargo.toml | 1 + src/poldercast/vicinity.rs | 4 +++- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/Cargo.toml b/Cargo.toml index 763ea7d..6fce6bf 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -18,6 +18,7 @@ rand = "0.7" hex = "0.4" serde = { version = "1.0", features = ["derive"] } thiserror = "1.0" +rayon = "1.3.0" [dev-dependencies] rand_chacha = "0.2" diff --git a/src/poldercast/vicinity.rs b/src/poldercast/vicinity.rs index 4d9baf4..7616a47 100644 --- a/src/poldercast/vicinity.rs +++ b/src/poldercast/vicinity.rs @@ -1,4 +1,5 @@ use crate::{GossipsBuilder, Id, Layer, Node, NodeProfile, Nodes, ViewBuilder}; +use rayon::prelude::*; const VICINITY_MAX_VIEW_SIZE: usize = 20; const VICINITY_MAX_GOSSIP_LENGTH: usize = 10; @@ -75,7 +76,8 @@ impl Vicinity { mut profiles: Vec<&Node>, max: usize, ) -> Vec { - profiles.sort_by(|left, right| { + // Use unstable parallel sort as total number of nodes can be quite large. + profiles.par_sort_unstable_by(|left, right| { to.proximity(left.profile()) .cmp(&to.proximity(right.profile())) });