From 4d9cf7a63e37fedca376d692f1461486d3dca659 Mon Sep 17 00:00:00 2001 From: itmilos Date: Mon, 17 Apr 2023 18:30:22 +0200 Subject: [PATCH 1/5] improve run_benchmark --- bin/node/bench/Cargo.toml | 1 + bin/node/bench/src/core.rs | 21 +++++++++++++-------- 2 files changed, 14 insertions(+), 8 deletions(-) diff --git a/bin/node/bench/Cargo.toml b/bin/node/bench/Cargo.toml index 153a721da41f..b564b4b68c41 100644 --- a/bin/node/bench/Cargo.toml +++ b/bin/node/bench/Cargo.toml @@ -39,6 +39,7 @@ fs_extra = "1" rand = { version = "0.8.5", features = ["small_rng"] } lazy_static = "1.4.0" parity-db = "0.4.6" +rayon = "1.7" sc-transaction-pool = { version = "4.0.0-dev", path = "../../../client/transaction-pool" } sc-transaction-pool-api = { version = "4.0.0-dev", path = "../../../client/transaction-pool/api" } futures = { version = "0.3.21", features = ["thread-pool"] } diff --git a/bin/node/bench/src/core.rs b/bin/node/bench/src/core.rs index 29cda70990aa..342744c1e3bc 100644 --- a/bin/node/bench/src/core.rs +++ b/bin/node/bench/src/core.rs @@ -17,6 +17,7 @@ // along with this program. If not, see . use serde::Serialize; +use rayon::prelude::*; use std::{ borrow::{Cow, ToOwned}, fmt, @@ -126,18 +127,22 @@ pub fn run_benchmark(benchmark: Box, mode: Mode) -> Be let name = benchmark.name().to_owned(); let mut benchmark = benchmark.setup(); - let mut durations: Vec = vec![]; - for _ in 0..50 { - let duration = benchmark.run(mode); - durations.push(duration.as_nanos()); - } + let durations: Vec = (0..50) + .into_par_iter() + .map(|_| benchmark.run(mode).as_nanos()) + .collect(); - durations.sort(); + let mut sorted_durations = durations.clone(); + sorted_durations.par_sort_unstable(); let raw_average = (durations.iter().sum::() / (durations.len() as u128)) as u64; - let average = (durations.iter().skip(10).take(30).sum::() / 30) as u64; + let average = (sorted_durations.iter().skip(10).take(30).sum::() / 30) as u64; - BenchmarkOutput { name: name.into(), raw_average, average } + BenchmarkOutput { + name: name.into(), + raw_average, + average, + } } macro_rules! matrix( From 53c51d109f4c715c0aecd0c47ae01d98437d234a Mon Sep 17 00:00:00 2001 From: itmilos Date: Tue, 18 Apr 2023 00:49:21 +0200 Subject: [PATCH 2/5] Revert "improve run_benchmark" This reverts commit 4d9cf7a63e37fedca376d692f1461486d3dca659. --- bin/node/bench/Cargo.toml | 1 - bin/node/bench/src/core.rs | 21 ++++++++------------- 2 files changed, 8 insertions(+), 14 deletions(-) diff --git a/bin/node/bench/Cargo.toml b/bin/node/bench/Cargo.toml index b564b4b68c41..153a721da41f 100644 --- a/bin/node/bench/Cargo.toml +++ b/bin/node/bench/Cargo.toml @@ -39,7 +39,6 @@ fs_extra = "1" rand = { version = "0.8.5", features = ["small_rng"] } lazy_static = "1.4.0" parity-db = "0.4.6" -rayon = "1.7" sc-transaction-pool = { version = "4.0.0-dev", path = "../../../client/transaction-pool" } sc-transaction-pool-api = { version = "4.0.0-dev", path = "../../../client/transaction-pool/api" } futures = { version = "0.3.21", features = ["thread-pool"] } diff --git a/bin/node/bench/src/core.rs b/bin/node/bench/src/core.rs index 99a8150021bf..1f22d3db6926 100644 --- a/bin/node/bench/src/core.rs +++ b/bin/node/bench/src/core.rs @@ -17,7 +17,6 @@ // along with this program. If not, see . use serde::Serialize; -use rayon::prelude::*; use std::{ borrow::{Cow, ToOwned}, fmt, @@ -116,22 +115,18 @@ pub fn run_benchmark(benchmark: Box, mode: Mode) -> Be let name = benchmark.name().to_owned(); let mut benchmark = benchmark.setup(); - let durations: Vec = (0..50) - .into_par_iter() - .map(|_| benchmark.run(mode).as_nanos()) - .collect(); + let mut durations: Vec = vec![]; + for _ in 0..50 { + let duration = benchmark.run(mode); + durations.push(duration.as_nanos()); + } - let mut sorted_durations = durations.clone(); - sorted_durations.par_sort_unstable(); + durations.sort(); let raw_average = (durations.iter().sum::() / (durations.len() as u128)) as u64; - let average = (sorted_durations.iter().skip(10).take(30).sum::() / 30) as u64; + let average = (durations.iter().skip(10).take(30).sum::() / 30) as u64; - BenchmarkOutput { - name: name.into(), - raw_average, - average, - } + BenchmarkOutput { name: name.into(), raw_average, average } } macro_rules! matrix( From 2f04bed856a7194e238e7281a118d23ca1a8da55 Mon Sep 17 00:00:00 2001 From: itmilos Date: Tue, 18 Apr 2023 00:54:29 +0200 Subject: [PATCH 3/5] improve has_good_judgement --- bin/node/runtime/src/impls.rs | 17 +++++++---------- 1 file changed, 7 insertions(+), 10 deletions(-) diff --git a/bin/node/runtime/src/impls.rs b/bin/node/runtime/src/impls.rs index 033549549a73..fedce896e7e6 100644 --- a/bin/node/runtime/src/impls.rs +++ b/bin/node/runtime/src/impls.rs @@ -60,16 +60,13 @@ impl IdentityVerifier for AllianceIdentityVerifier { } fn has_good_judgement(who: &AccountId) -> bool { - use pallet_identity::Judgement; - if let Some(judgements) = - crate::Identity::identity(who).map(|registration| registration.judgements) - { - judgements - .iter() - .any(|(_, j)| matches!(j, Judgement::KnownGood | Judgement::Reasonable)) - } else { - false - } + crate::Identity::identity(who) + .map(|registration| registration.judgements) + .map_or(false, |judgements| { + judgements.iter().any(|(_, j)| { + matches!(j, Judgement::KnownGood | Judgement::Reasonable) + }) + }) } fn super_account_id(who: &AccountId) -> Option { From 17be838e28dfeb93142b04adee9e480eb4bf3439 Mon Sep 17 00:00:00 2001 From: Oliver Tale-Yazdi Date: Wed, 19 Apr 2023 10:32:41 +0200 Subject: [PATCH 4/5] Update bin/node/runtime/src/impls.rs --- bin/node/runtime/src/impls.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/bin/node/runtime/src/impls.rs b/bin/node/runtime/src/impls.rs index fedce896e7e6..92d0b6af76db 100644 --- a/bin/node/runtime/src/impls.rs +++ b/bin/node/runtime/src/impls.rs @@ -60,6 +60,7 @@ impl IdentityVerifier for AllianceIdentityVerifier { } fn has_good_judgement(who: &AccountId) -> bool { + use pallet_identity::Judgement; crate::Identity::identity(who) .map(|registration| registration.judgements) .map_or(false, |judgements| { From 54be92c1cadbfc2687d5e226f3426a29b841df8e Mon Sep 17 00:00:00 2001 From: command-bot <> Date: Wed, 19 Apr 2023 08:37:52 +0000 Subject: [PATCH 5/5] ".git/.scripts/commands/fmt/fmt.sh" --- bin/node/runtime/src/impls.rs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/bin/node/runtime/src/impls.rs b/bin/node/runtime/src/impls.rs index 92d0b6af76db..05531f47c6e0 100644 --- a/bin/node/runtime/src/impls.rs +++ b/bin/node/runtime/src/impls.rs @@ -64,9 +64,9 @@ impl IdentityVerifier for AllianceIdentityVerifier { crate::Identity::identity(who) .map(|registration| registration.judgements) .map_or(false, |judgements| { - judgements.iter().any(|(_, j)| { - matches!(j, Judgement::KnownGood | Judgement::Reasonable) - }) + judgements + .iter() + .any(|(_, j)| matches!(j, Judgement::KnownGood | Judgement::Reasonable)) }) }