From 409306c39b94280c08fb8fe1712ab7d518957447 Mon Sep 17 00:00:00 2001 From: kianenigma Date: Mon, 5 Jul 2021 15:40:38 +0200 Subject: [PATCH 1/7] Store election snapshot in a more memory-friendly way. --- .../election-provider-multi-phase/src/lib.rs | 29 +++++++++++++++---- 1 file changed, 23 insertions(+), 6 deletions(-) diff --git a/frame/election-provider-multi-phase/src/lib.rs b/frame/election-provider-multi-phase/src/lib.rs index 6c92f2b157180..378037ac5e470 100644 --- a/frame/election-provider-multi-phase/src/lib.rs +++ b/frame/election-provider-multi-phase/src/lib.rs @@ -318,7 +318,7 @@ impl BenchmarkingConfig for () { } /// Current phase of the pallet. -#[derive(PartialEq, Eq, Clone, Copy, Encode, Decode, RuntimeDebug)] +#[derive(PartialEq, Eq, Clone, Copy, Encode, Decode, Debug)] pub enum Phase { /// Nothing, the election is not happening. Off, @@ -393,7 +393,7 @@ pub enum FallbackStrategy { } /// The type of `Computation` that provided this election data. -#[derive(PartialEq, Eq, Clone, Copy, Encode, Decode, RuntimeDebug)] +#[derive(PartialEq, Eq, Clone, Copy, Encode, Decode, Debug)] pub enum ElectionCompute { /// Election was computed on-chain. OnChain, @@ -465,7 +465,7 @@ pub struct RoundSnapshot { /// This is stored automatically on-chain, and it contains the **size of the entire snapshot**. /// This is also used in dispatchables as weight witness data and should **only contain the size of /// the presented solution**, not the entire snapshot. -#[derive(PartialEq, Eq, Clone, Copy, Encode, Decode, RuntimeDebug, Default)] +#[derive(PartialEq, Eq, Clone, Copy, Encode, Decode, Debug, Default)] pub struct SolutionOrSnapshotSize { /// The length of voters. #[codec(compact)] @@ -1287,12 +1287,29 @@ impl Pallet { } // Only write snapshot if all existed. - >::put(SolutionOrSnapshotSize { + let metadata = SolutionOrSnapshotSize { voters: voters.len() as u32, targets: targets.len() as u32, - }); + }; + log!(debug, "creating a snapshot with metadata {:?}", metadata); + + >::put(metadata); >::put(desired_targets); - >::put(RoundSnapshot { voters, targets }); + + // instead of using storage APIs, we do a manual encoding into a fixed-size buffer. + // encode it without storing it anywhere, this should not cause any allocation. + let snapshot = RoundSnapshot { voters, targets }; + let size = snapshot.encoded_size(); + log!(info, "snapshot pre-calculated size {:?}", size); + let mut buffer = Vec::with_capacity(size); + snapshot.encode_to(&mut buffer); + + // do some checks. + debug_assert_eq!(buffer, snapshot.encode()); + // buffer should have not re-allocated since. + debug_assert_eq!(buffer.len(), size); + + sp_io::storage::set(&>::hashed_key(), &buffer); Ok(w1.saturating_add(w2).saturating_add(w3).saturating_add(T::DbWeight::get().writes(3))) } From 2953b524d9639ef56063ca1945cf4c022eb6daa2 Mon Sep 17 00:00:00 2001 From: kianenigma Date: Mon, 5 Jul 2021 19:26:21 +0200 Subject: [PATCH 2/7] fix --- frame/election-provider-multi-phase/src/lib.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/frame/election-provider-multi-phase/src/lib.rs b/frame/election-provider-multi-phase/src/lib.rs index 378037ac5e470..a5a22ebef3fa5 100644 --- a/frame/election-provider-multi-phase/src/lib.rs +++ b/frame/election-provider-multi-phase/src/lib.rs @@ -1307,7 +1307,7 @@ impl Pallet { // do some checks. debug_assert_eq!(buffer, snapshot.encode()); // buffer should have not re-allocated since. - debug_assert_eq!(buffer.len(), size); + debug_assert!(buffer.len() == size && size == buffer.capacity()); sp_io::storage::set(&>::hashed_key(), &buffer); Ok(w1.saturating_add(w2).saturating_add(w3).saturating_add(T::DbWeight::get().writes(3))) From 2e97d9d3717ab8a448a01ddc9dffd887825d1d62 Mon Sep 17 00:00:00 2001 From: kianenigma Date: Mon, 5 Jul 2021 19:32:59 +0200 Subject: [PATCH 3/7] re-order benchmarks --- .../src/benchmarking.rs | 33 +++++++------------ 1 file changed, 12 insertions(+), 21 deletions(-) diff --git a/frame/election-provider-multi-phase/src/benchmarking.rs b/frame/election-provider-multi-phase/src/benchmarking.rs index 7988163e98f65..4570a83e676dd 100644 --- a/frame/election-provider-multi-phase/src/benchmarking.rs +++ b/frame/election-provider-multi-phase/src/benchmarking.rs @@ -176,6 +176,18 @@ frame_benchmarking::benchmarks! { assert!(>::current_phase().is_unsigned()); } + on_initialize_open_unsigned_without_snapshot { + // need to assume signed phase was open before + >::on_initialize_open_signed().unwrap(); + assert!(>::snapshot().is_some()); + assert!(>::current_phase().is_signed()); + }: { + >::on_initialize_open_unsigned(false, true, 1u32.into()).unwrap(); + } verify { + assert!(>::snapshot().is_some()); + assert!(>::current_phase().is_unsigned()); + } + finalize_signed_phase_accept_solution { let receiver = account("receiver", 0, SEED); let initial_balance = T::Currency::minimum_balance() * 10u32.into(); @@ -209,18 +221,6 @@ frame_benchmarking::benchmarks! { assert_eq!(T::Currency::reserved_balance(&receiver), 0u32.into()); } - on_initialize_open_unsigned_without_snapshot { - // need to assume signed phase was open before - >::on_initialize_open_signed().unwrap(); - assert!(>::snapshot().is_some()); - assert!(>::current_phase().is_signed()); - }: { - >::on_initialize_open_unsigned(false, true, 1u32.into()).unwrap(); - } verify { - assert!(>::snapshot().is_some()); - assert!(>::current_phase().is_unsigned()); - } - // a call to `::elect` where we only return the queued solution. elect_queued { // assume largest values for the election status. These will merely affect the decoding. @@ -251,15 +251,6 @@ frame_benchmarking::benchmarks! { assert_eq!(>::get(), >::Off); } - #[extra] - create_snapshot { - assert!(>::snapshot().is_none()); - }: { - >::create_snapshot().unwrap() - } verify { - assert!(>::snapshot().is_some()); - } - submit { let c in 1 .. (T::SignedMaxSubmissions::get() - 1); From 8fd046fa5a4194013ad87497bf25dd6feb64b6ea Mon Sep 17 00:00:00 2001 From: Kian Paimani <5588131+kianenigma@users.noreply.github.com> Date: Wed, 7 Jul 2021 10:27:20 +0200 Subject: [PATCH 4/7] Update frame/election-provider-multi-phase/src/lib.rs Co-authored-by: Guillaume Thiolliere --- frame/election-provider-multi-phase/src/lib.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/frame/election-provider-multi-phase/src/lib.rs b/frame/election-provider-multi-phase/src/lib.rs index a5a22ebef3fa5..66ee070298d8f 100644 --- a/frame/election-provider-multi-phase/src/lib.rs +++ b/frame/election-provider-multi-phase/src/lib.rs @@ -1297,7 +1297,7 @@ impl Pallet { >::put(desired_targets); // instead of using storage APIs, we do a manual encoding into a fixed-size buffer. - // encode it without storing it anywhere, this should not cause any allocation. + // `encoded_size` encodes it without storing it anywhere, this should not cause any allocation. let snapshot = RoundSnapshot { voters, targets }; let size = snapshot.encoded_size(); log!(info, "snapshot pre-calculated size {:?}", size); From 3adee7c3414fab53df90611c51da4a76a68d0c91 Mon Sep 17 00:00:00 2001 From: Parity Bot Date: Wed, 7 Jul 2021 10:58:55 +0000 Subject: [PATCH 5/7] cargo run --release --features=runtime-benchmarks --manifest-path=bin/node/cli/Cargo.toml -- benchmark --chain=dev --steps=50 --repeat=20 --pallet=pallet_election_provider_multi_phase --extrinsic=* --execution=wasm --wasm-execution=compiled --heap-pages=4096 --output=./frame/election-provider-multi-phase/src/weights.rs --template=./.maintain/frame-weight-template.hbs --- .../src/weights.rs | 244 ++++++++++++++---- 1 file changed, 193 insertions(+), 51 deletions(-) diff --git a/frame/election-provider-multi-phase/src/weights.rs b/frame/election-provider-multi-phase/src/weights.rs index 6a245ebb51254..b6383aefd93a7 100644 --- a/frame/election-provider-multi-phase/src/weights.rs +++ b/frame/election-provider-multi-phase/src/weights.rs @@ -18,7 +18,7 @@ //! Autogenerated weights for pallet_election_provider_multi_phase //! //! THIS FILE WAS AUTO-GENERATED USING THE SUBSTRATE BENCHMARK CLI VERSION 3.0.0 -//! DATE: 2021-06-20, STEPS: `[50, ]`, REPEAT: 20, LOW RANGE: `[]`, HIGH RANGE: `[]` +//! DATE: 2021-07-07, STEPS: `[50, ]`, REPEAT: 20, LOW RANGE: `[]`, HIGH RANGE: `[]` //! EXECUTION: Some(Wasm), WASM-EXECUTION: Compiled, CHAIN: Some("dev"), DB CACHE: 128 // Executed Command: @@ -54,75 +54,151 @@ pub trait WeightInfo { fn submit(c: u32, ) -> Weight; fn submit_unsigned(v: u32, t: u32, a: u32, d: u32, ) -> Weight; fn feasibility_check(v: u32, t: u32, a: u32, d: u32, ) -> Weight; + fn on_initialize_nothing() -> Weight; + fn on_initialize_open_signed() -> Weight; + fn on_initialize_open_unsigned_with_snapshot() -> Weight; + fn finalize_signed_phase_accept_solution() -> Weight; + fn finalize_signed_phase_reject_solution() -> Weight; + fn on_initialize_open_unsigned_without_snapshot() -> Weight; + fn elect_queued() -> Weight; + fn submit(c: u32, ) -> Weight; + fn submit_unsigned(v: u32, t: u32, a: u32, d: u32, ) -> Weight; + fn feasibility_check(v: u32, t: u32, a: u32, d: u32, ) -> Weight; } /// Weights for pallet_election_provider_multi_phase using the Substrate node and recommended hardware. pub struct SubstrateWeight(PhantomData); impl WeightInfo for SubstrateWeight { fn on_initialize_nothing() -> Weight { - (33_392_000 as Weight) + (34_616_000 as Weight) .saturating_add(T::DbWeight::get().reads(8 as Weight)) } fn on_initialize_open_signed() -> Weight { - (115_659_000 as Weight) + (151_793_000 as Weight) .saturating_add(T::DbWeight::get().reads(10 as Weight)) .saturating_add(T::DbWeight::get().writes(4 as Weight)) } fn on_initialize_open_unsigned_with_snapshot() -> Weight { - (114_970_000 as Weight) + (150_105_000 as Weight) .saturating_add(T::DbWeight::get().reads(10 as Weight)) .saturating_add(T::DbWeight::get().writes(4 as Weight)) } fn finalize_signed_phase_accept_solution() -> Weight { - (51_442_000 as Weight) + (61_264_000 as Weight) .saturating_add(T::DbWeight::get().reads(1 as Weight)) .saturating_add(T::DbWeight::get().writes(2 as Weight)) } fn finalize_signed_phase_reject_solution() -> Weight { - (23_160_000 as Weight) + (40_576_000 as Weight) .saturating_add(T::DbWeight::get().reads(1 as Weight)) .saturating_add(T::DbWeight::get().writes(1 as Weight)) } fn on_initialize_open_unsigned_without_snapshot() -> Weight { - (24_101_000 as Weight) + (48_203_000 as Weight) .saturating_add(T::DbWeight::get().reads(1 as Weight)) .saturating_add(T::DbWeight::get().writes(1 as Weight)) } fn elect_queued() -> Weight { - (6_153_604_000 as Weight) - .saturating_add(T::DbWeight::get().reads(5 as Weight)) + (6_260_652_000 as Weight) + .saturating_add(T::DbWeight::get().reads(6 as Weight)) .saturating_add(T::DbWeight::get().writes(8 as Weight)) } fn submit(c: u32, ) -> Weight { - (78_972_000 as Weight) + (80_394_000 as Weight) // Standard Error: 16_000 - .saturating_add((308_000 as Weight).saturating_mul(c as Weight)) + .saturating_add((778_000 as Weight).saturating_mul(c as Weight)) .saturating_add(T::DbWeight::get().reads(4 as Weight)) .saturating_add(T::DbWeight::get().writes(3 as Weight)) } fn submit_unsigned(v: u32, t: u32, a: u32, d: u32, ) -> Weight { (0 as Weight) - // Standard Error: 12_000 - .saturating_add((3_572_000 as Weight).saturating_mul(v as Weight)) - // Standard Error: 42_000 - .saturating_add((23_000 as Weight).saturating_mul(t as Weight)) - // Standard Error: 12_000 - .saturating_add((11_529_000 as Weight).saturating_mul(a as Weight)) - // Standard Error: 63_000 - .saturating_add((3_333_000 as Weight).saturating_mul(d as Weight)) + // Standard Error: 13_000 + .saturating_add((3_563_000 as Weight).saturating_mul(v as Weight)) + // Standard Error: 46_000 + .saturating_add((183_000 as Weight).saturating_mul(t as Weight)) + // Standard Error: 13_000 + .saturating_add((11_627_000 as Weight).saturating_mul(a as Weight)) + // Standard Error: 69_000 + .saturating_add((2_927_000 as Weight).saturating_mul(d as Weight)) .saturating_add(T::DbWeight::get().reads(7 as Weight)) .saturating_add(T::DbWeight::get().writes(1 as Weight)) } fn feasibility_check(v: u32, t: u32, a: u32, d: u32, ) -> Weight { (0 as Weight) - // Standard Error: 7_000 - .saturating_add((3_647_000 as Weight).saturating_mul(v as Weight)) - // Standard Error: 23_000 - .saturating_add((390_000 as Weight).saturating_mul(t as Weight)) - // Standard Error: 7_000 - .saturating_add((9_614_000 as Weight).saturating_mul(a as Weight)) + // Standard Error: 9_000 + .saturating_add((3_606_000 as Weight).saturating_mul(v as Weight)) + // Standard Error: 30_000 + .saturating_add((514_000 as Weight).saturating_mul(t as Weight)) + // Standard Error: 9_000 + .saturating_add((9_736_000 as Weight).saturating_mul(a as Weight)) + // Standard Error: 45_000 + .saturating_add((3_337_000 as Weight).saturating_mul(d as Weight)) + .saturating_add(T::DbWeight::get().reads(4 as Weight)) + } + fn on_initialize_nothing() -> Weight { + (34_130_000 as Weight) + .saturating_add(T::DbWeight::get().reads(8 as Weight)) + } + fn on_initialize_open_signed() -> Weight { + (151_767_000 as Weight) + .saturating_add(T::DbWeight::get().reads(10 as Weight)) + .saturating_add(T::DbWeight::get().writes(4 as Weight)) + } + fn on_initialize_open_unsigned_with_snapshot() -> Weight { + (148_743_000 as Weight) + .saturating_add(T::DbWeight::get().reads(10 as Weight)) + .saturating_add(T::DbWeight::get().writes(4 as Weight)) + } + fn finalize_signed_phase_accept_solution() -> Weight { + (62_060_000 as Weight) + .saturating_add(T::DbWeight::get().reads(1 as Weight)) + .saturating_add(T::DbWeight::get().writes(2 as Weight)) + } + fn finalize_signed_phase_reject_solution() -> Weight { + (41_397_000 as Weight) + .saturating_add(T::DbWeight::get().reads(1 as Weight)) + .saturating_add(T::DbWeight::get().writes(1 as Weight)) + } + fn on_initialize_open_unsigned_without_snapshot() -> Weight { + (30_862_000 as Weight) + .saturating_add(T::DbWeight::get().reads(1 as Weight)) + .saturating_add(T::DbWeight::get().writes(1 as Weight)) + } + fn elect_queued() -> Weight { + (6_138_573_000 as Weight) + .saturating_add(T::DbWeight::get().reads(6 as Weight)) + .saturating_add(T::DbWeight::get().writes(8 as Weight)) + } + fn submit(c: u32, ) -> Weight { + (79_744_000 as Weight) // Standard Error: 35_000 - .saturating_add((3_405_000 as Weight).saturating_mul(d as Weight)) + .saturating_add((668_000 as Weight).saturating_mul(c as Weight)) + .saturating_add(T::DbWeight::get().reads(4 as Weight)) + .saturating_add(T::DbWeight::get().writes(3 as Weight)) + } + fn submit_unsigned(v: u32, t: u32, a: u32, d: u32, ) -> Weight { + (0 as Weight) + // Standard Error: 13_000 + .saturating_add((3_546_000 as Weight).saturating_mul(v as Weight)) + // Standard Error: 45_000 + .saturating_add((81_000 as Weight).saturating_mul(t as Weight)) + // Standard Error: 13_000 + .saturating_add((11_644_000 as Weight).saturating_mul(a as Weight)) + // Standard Error: 68_000 + .saturating_add((3_315_000 as Weight).saturating_mul(d as Weight)) + .saturating_add(T::DbWeight::get().reads(7 as Weight)) + .saturating_add(T::DbWeight::get().writes(1 as Weight)) + } + fn feasibility_check(v: u32, t: u32, a: u32, d: u32, ) -> Weight { + (0 as Weight) + // Standard Error: 9_000 + .saturating_add((3_619_000 as Weight).saturating_mul(v as Weight)) + // Standard Error: 30_000 + .saturating_add((327_000 as Weight).saturating_mul(t as Weight)) + // Standard Error: 9_000 + .saturating_add((9_745_000 as Weight).saturating_mul(a as Weight)) + // Standard Error: 45_000 + .saturating_add((3_436_000 as Weight).saturating_mul(d as Weight)) .saturating_add(T::DbWeight::get().reads(4 as Weight)) } } @@ -130,69 +206,135 @@ impl WeightInfo for SubstrateWeight { // For backwards compatibility and tests impl WeightInfo for () { fn on_initialize_nothing() -> Weight { - (33_392_000 as Weight) + (34_616_000 as Weight) .saturating_add(RocksDbWeight::get().reads(8 as Weight)) } fn on_initialize_open_signed() -> Weight { - (115_659_000 as Weight) + (151_793_000 as Weight) .saturating_add(RocksDbWeight::get().reads(10 as Weight)) .saturating_add(RocksDbWeight::get().writes(4 as Weight)) } fn on_initialize_open_unsigned_with_snapshot() -> Weight { - (114_970_000 as Weight) + (150_105_000 as Weight) .saturating_add(RocksDbWeight::get().reads(10 as Weight)) .saturating_add(RocksDbWeight::get().writes(4 as Weight)) } fn finalize_signed_phase_accept_solution() -> Weight { - (51_442_000 as Weight) + (61_264_000 as Weight) .saturating_add(RocksDbWeight::get().reads(1 as Weight)) .saturating_add(RocksDbWeight::get().writes(2 as Weight)) } fn finalize_signed_phase_reject_solution() -> Weight { - (23_160_000 as Weight) + (40_576_000 as Weight) .saturating_add(RocksDbWeight::get().reads(1 as Weight)) .saturating_add(RocksDbWeight::get().writes(1 as Weight)) } fn on_initialize_open_unsigned_without_snapshot() -> Weight { - (24_101_000 as Weight) + (48_203_000 as Weight) .saturating_add(RocksDbWeight::get().reads(1 as Weight)) .saturating_add(RocksDbWeight::get().writes(1 as Weight)) } fn elect_queued() -> Weight { - (6_153_604_000 as Weight) - .saturating_add(RocksDbWeight::get().reads(5 as Weight)) + (6_260_652_000 as Weight) + .saturating_add(RocksDbWeight::get().reads(6 as Weight)) .saturating_add(RocksDbWeight::get().writes(8 as Weight)) } fn submit(c: u32, ) -> Weight { - (78_972_000 as Weight) + (80_394_000 as Weight) // Standard Error: 16_000 - .saturating_add((308_000 as Weight).saturating_mul(c as Weight)) + .saturating_add((778_000 as Weight).saturating_mul(c as Weight)) .saturating_add(RocksDbWeight::get().reads(4 as Weight)) .saturating_add(RocksDbWeight::get().writes(3 as Weight)) } fn submit_unsigned(v: u32, t: u32, a: u32, d: u32, ) -> Weight { (0 as Weight) - // Standard Error: 12_000 - .saturating_add((3_572_000 as Weight).saturating_mul(v as Weight)) - // Standard Error: 42_000 - .saturating_add((23_000 as Weight).saturating_mul(t as Weight)) - // Standard Error: 12_000 - .saturating_add((11_529_000 as Weight).saturating_mul(a as Weight)) - // Standard Error: 63_000 - .saturating_add((3_333_000 as Weight).saturating_mul(d as Weight)) + // Standard Error: 13_000 + .saturating_add((3_563_000 as Weight).saturating_mul(v as Weight)) + // Standard Error: 46_000 + .saturating_add((183_000 as Weight).saturating_mul(t as Weight)) + // Standard Error: 13_000 + .saturating_add((11_627_000 as Weight).saturating_mul(a as Weight)) + // Standard Error: 69_000 + .saturating_add((2_927_000 as Weight).saturating_mul(d as Weight)) .saturating_add(RocksDbWeight::get().reads(7 as Weight)) .saturating_add(RocksDbWeight::get().writes(1 as Weight)) } fn feasibility_check(v: u32, t: u32, a: u32, d: u32, ) -> Weight { (0 as Weight) - // Standard Error: 7_000 - .saturating_add((3_647_000 as Weight).saturating_mul(v as Weight)) - // Standard Error: 23_000 - .saturating_add((390_000 as Weight).saturating_mul(t as Weight)) - // Standard Error: 7_000 - .saturating_add((9_614_000 as Weight).saturating_mul(a as Weight)) + // Standard Error: 9_000 + .saturating_add((3_606_000 as Weight).saturating_mul(v as Weight)) + // Standard Error: 30_000 + .saturating_add((514_000 as Weight).saturating_mul(t as Weight)) + // Standard Error: 9_000 + .saturating_add((9_736_000 as Weight).saturating_mul(a as Weight)) + // Standard Error: 45_000 + .saturating_add((3_337_000 as Weight).saturating_mul(d as Weight)) + .saturating_add(RocksDbWeight::get().reads(4 as Weight)) + } + fn on_initialize_nothing() -> Weight { + (34_130_000 as Weight) + .saturating_add(RocksDbWeight::get().reads(8 as Weight)) + } + fn on_initialize_open_signed() -> Weight { + (151_767_000 as Weight) + .saturating_add(RocksDbWeight::get().reads(10 as Weight)) + .saturating_add(RocksDbWeight::get().writes(4 as Weight)) + } + fn on_initialize_open_unsigned_with_snapshot() -> Weight { + (148_743_000 as Weight) + .saturating_add(RocksDbWeight::get().reads(10 as Weight)) + .saturating_add(RocksDbWeight::get().writes(4 as Weight)) + } + fn finalize_signed_phase_accept_solution() -> Weight { + (62_060_000 as Weight) + .saturating_add(RocksDbWeight::get().reads(1 as Weight)) + .saturating_add(RocksDbWeight::get().writes(2 as Weight)) + } + fn finalize_signed_phase_reject_solution() -> Weight { + (41_397_000 as Weight) + .saturating_add(RocksDbWeight::get().reads(1 as Weight)) + .saturating_add(RocksDbWeight::get().writes(1 as Weight)) + } + fn on_initialize_open_unsigned_without_snapshot() -> Weight { + (30_862_000 as Weight) + .saturating_add(RocksDbWeight::get().reads(1 as Weight)) + .saturating_add(RocksDbWeight::get().writes(1 as Weight)) + } + fn elect_queued() -> Weight { + (6_138_573_000 as Weight) + .saturating_add(RocksDbWeight::get().reads(6 as Weight)) + .saturating_add(RocksDbWeight::get().writes(8 as Weight)) + } + fn submit(c: u32, ) -> Weight { + (79_744_000 as Weight) // Standard Error: 35_000 - .saturating_add((3_405_000 as Weight).saturating_mul(d as Weight)) + .saturating_add((668_000 as Weight).saturating_mul(c as Weight)) + .saturating_add(RocksDbWeight::get().reads(4 as Weight)) + .saturating_add(RocksDbWeight::get().writes(3 as Weight)) + } + fn submit_unsigned(v: u32, t: u32, a: u32, d: u32, ) -> Weight { + (0 as Weight) + // Standard Error: 13_000 + .saturating_add((3_546_000 as Weight).saturating_mul(v as Weight)) + // Standard Error: 45_000 + .saturating_add((81_000 as Weight).saturating_mul(t as Weight)) + // Standard Error: 13_000 + .saturating_add((11_644_000 as Weight).saturating_mul(a as Weight)) + // Standard Error: 68_000 + .saturating_add((3_315_000 as Weight).saturating_mul(d as Weight)) + .saturating_add(RocksDbWeight::get().reads(7 as Weight)) + .saturating_add(RocksDbWeight::get().writes(1 as Weight)) + } + fn feasibility_check(v: u32, t: u32, a: u32, d: u32, ) -> Weight { + (0 as Weight) + // Standard Error: 9_000 + .saturating_add((3_619_000 as Weight).saturating_mul(v as Weight)) + // Standard Error: 30_000 + .saturating_add((327_000 as Weight).saturating_mul(t as Weight)) + // Standard Error: 9_000 + .saturating_add((9_745_000 as Weight).saturating_mul(a as Weight)) + // Standard Error: 45_000 + .saturating_add((3_436_000 as Weight).saturating_mul(d as Weight)) .saturating_add(RocksDbWeight::get().reads(4 as Weight)) } } From adb9927a15a140957e12eff9dbd56f1541c6e42c Mon Sep 17 00:00:00 2001 From: kianenigma Date: Thu, 8 Jul 2021 13:37:53 +0200 Subject: [PATCH 6/7] manually fix the weights --- .../src/weights.rs | 142 ------------------ 1 file changed, 142 deletions(-) diff --git a/frame/election-provider-multi-phase/src/weights.rs b/frame/election-provider-multi-phase/src/weights.rs index b6383aefd93a7..0f8fe54fc5108 100644 --- a/frame/election-provider-multi-phase/src/weights.rs +++ b/frame/election-provider-multi-phase/src/weights.rs @@ -54,87 +54,11 @@ pub trait WeightInfo { fn submit(c: u32, ) -> Weight; fn submit_unsigned(v: u32, t: u32, a: u32, d: u32, ) -> Weight; fn feasibility_check(v: u32, t: u32, a: u32, d: u32, ) -> Weight; - fn on_initialize_nothing() -> Weight; - fn on_initialize_open_signed() -> Weight; - fn on_initialize_open_unsigned_with_snapshot() -> Weight; - fn finalize_signed_phase_accept_solution() -> Weight; - fn finalize_signed_phase_reject_solution() -> Weight; - fn on_initialize_open_unsigned_without_snapshot() -> Weight; - fn elect_queued() -> Weight; - fn submit(c: u32, ) -> Weight; - fn submit_unsigned(v: u32, t: u32, a: u32, d: u32, ) -> Weight; - fn feasibility_check(v: u32, t: u32, a: u32, d: u32, ) -> Weight; } /// Weights for pallet_election_provider_multi_phase using the Substrate node and recommended hardware. pub struct SubstrateWeight(PhantomData); impl WeightInfo for SubstrateWeight { - fn on_initialize_nothing() -> Weight { - (34_616_000 as Weight) - .saturating_add(T::DbWeight::get().reads(8 as Weight)) - } - fn on_initialize_open_signed() -> Weight { - (151_793_000 as Weight) - .saturating_add(T::DbWeight::get().reads(10 as Weight)) - .saturating_add(T::DbWeight::get().writes(4 as Weight)) - } - fn on_initialize_open_unsigned_with_snapshot() -> Weight { - (150_105_000 as Weight) - .saturating_add(T::DbWeight::get().reads(10 as Weight)) - .saturating_add(T::DbWeight::get().writes(4 as Weight)) - } - fn finalize_signed_phase_accept_solution() -> Weight { - (61_264_000 as Weight) - .saturating_add(T::DbWeight::get().reads(1 as Weight)) - .saturating_add(T::DbWeight::get().writes(2 as Weight)) - } - fn finalize_signed_phase_reject_solution() -> Weight { - (40_576_000 as Weight) - .saturating_add(T::DbWeight::get().reads(1 as Weight)) - .saturating_add(T::DbWeight::get().writes(1 as Weight)) - } - fn on_initialize_open_unsigned_without_snapshot() -> Weight { - (48_203_000 as Weight) - .saturating_add(T::DbWeight::get().reads(1 as Weight)) - .saturating_add(T::DbWeight::get().writes(1 as Weight)) - } - fn elect_queued() -> Weight { - (6_260_652_000 as Weight) - .saturating_add(T::DbWeight::get().reads(6 as Weight)) - .saturating_add(T::DbWeight::get().writes(8 as Weight)) - } - fn submit(c: u32, ) -> Weight { - (80_394_000 as Weight) - // Standard Error: 16_000 - .saturating_add((778_000 as Weight).saturating_mul(c as Weight)) - .saturating_add(T::DbWeight::get().reads(4 as Weight)) - .saturating_add(T::DbWeight::get().writes(3 as Weight)) - } - fn submit_unsigned(v: u32, t: u32, a: u32, d: u32, ) -> Weight { - (0 as Weight) - // Standard Error: 13_000 - .saturating_add((3_563_000 as Weight).saturating_mul(v as Weight)) - // Standard Error: 46_000 - .saturating_add((183_000 as Weight).saturating_mul(t as Weight)) - // Standard Error: 13_000 - .saturating_add((11_627_000 as Weight).saturating_mul(a as Weight)) - // Standard Error: 69_000 - .saturating_add((2_927_000 as Weight).saturating_mul(d as Weight)) - .saturating_add(T::DbWeight::get().reads(7 as Weight)) - .saturating_add(T::DbWeight::get().writes(1 as Weight)) - } - fn feasibility_check(v: u32, t: u32, a: u32, d: u32, ) -> Weight { - (0 as Weight) - // Standard Error: 9_000 - .saturating_add((3_606_000 as Weight).saturating_mul(v as Weight)) - // Standard Error: 30_000 - .saturating_add((514_000 as Weight).saturating_mul(t as Weight)) - // Standard Error: 9_000 - .saturating_add((9_736_000 as Weight).saturating_mul(a as Weight)) - // Standard Error: 45_000 - .saturating_add((3_337_000 as Weight).saturating_mul(d as Weight)) - .saturating_add(T::DbWeight::get().reads(4 as Weight)) - } fn on_initialize_nothing() -> Weight { (34_130_000 as Weight) .saturating_add(T::DbWeight::get().reads(8 as Weight)) @@ -205,72 +129,6 @@ impl WeightInfo for SubstrateWeight { // For backwards compatibility and tests impl WeightInfo for () { - fn on_initialize_nothing() -> Weight { - (34_616_000 as Weight) - .saturating_add(RocksDbWeight::get().reads(8 as Weight)) - } - fn on_initialize_open_signed() -> Weight { - (151_793_000 as Weight) - .saturating_add(RocksDbWeight::get().reads(10 as Weight)) - .saturating_add(RocksDbWeight::get().writes(4 as Weight)) - } - fn on_initialize_open_unsigned_with_snapshot() -> Weight { - (150_105_000 as Weight) - .saturating_add(RocksDbWeight::get().reads(10 as Weight)) - .saturating_add(RocksDbWeight::get().writes(4 as Weight)) - } - fn finalize_signed_phase_accept_solution() -> Weight { - (61_264_000 as Weight) - .saturating_add(RocksDbWeight::get().reads(1 as Weight)) - .saturating_add(RocksDbWeight::get().writes(2 as Weight)) - } - fn finalize_signed_phase_reject_solution() -> Weight { - (40_576_000 as Weight) - .saturating_add(RocksDbWeight::get().reads(1 as Weight)) - .saturating_add(RocksDbWeight::get().writes(1 as Weight)) - } - fn on_initialize_open_unsigned_without_snapshot() -> Weight { - (48_203_000 as Weight) - .saturating_add(RocksDbWeight::get().reads(1 as Weight)) - .saturating_add(RocksDbWeight::get().writes(1 as Weight)) - } - fn elect_queued() -> Weight { - (6_260_652_000 as Weight) - .saturating_add(RocksDbWeight::get().reads(6 as Weight)) - .saturating_add(RocksDbWeight::get().writes(8 as Weight)) - } - fn submit(c: u32, ) -> Weight { - (80_394_000 as Weight) - // Standard Error: 16_000 - .saturating_add((778_000 as Weight).saturating_mul(c as Weight)) - .saturating_add(RocksDbWeight::get().reads(4 as Weight)) - .saturating_add(RocksDbWeight::get().writes(3 as Weight)) - } - fn submit_unsigned(v: u32, t: u32, a: u32, d: u32, ) -> Weight { - (0 as Weight) - // Standard Error: 13_000 - .saturating_add((3_563_000 as Weight).saturating_mul(v as Weight)) - // Standard Error: 46_000 - .saturating_add((183_000 as Weight).saturating_mul(t as Weight)) - // Standard Error: 13_000 - .saturating_add((11_627_000 as Weight).saturating_mul(a as Weight)) - // Standard Error: 69_000 - .saturating_add((2_927_000 as Weight).saturating_mul(d as Weight)) - .saturating_add(RocksDbWeight::get().reads(7 as Weight)) - .saturating_add(RocksDbWeight::get().writes(1 as Weight)) - } - fn feasibility_check(v: u32, t: u32, a: u32, d: u32, ) -> Weight { - (0 as Weight) - // Standard Error: 9_000 - .saturating_add((3_606_000 as Weight).saturating_mul(v as Weight)) - // Standard Error: 30_000 - .saturating_add((514_000 as Weight).saturating_mul(t as Weight)) - // Standard Error: 9_000 - .saturating_add((9_736_000 as Weight).saturating_mul(a as Weight)) - // Standard Error: 45_000 - .saturating_add((3_337_000 as Weight).saturating_mul(d as Weight)) - .saturating_add(RocksDbWeight::get().reads(4 as Weight)) - } fn on_initialize_nothing() -> Weight { (34_130_000 as Weight) .saturating_add(RocksDbWeight::get().reads(8 as Weight)) From 1ba512336dc207a56f8639403971535cb5de7e2c Mon Sep 17 00:00:00 2001 From: kianenigma Date: Mon, 12 Jul 2021 16:02:07 +0200 Subject: [PATCH 7/7] remove todo --- frame/election-provider-multi-phase/src/benchmarking.rs | 1 - 1 file changed, 1 deletion(-) diff --git a/frame/election-provider-multi-phase/src/benchmarking.rs b/frame/election-provider-multi-phase/src/benchmarking.rs index 40f7ed9971554..6cf581135f144 100644 --- a/frame/election-provider-multi-phase/src/benchmarking.rs +++ b/frame/election-provider-multi-phase/src/benchmarking.rs @@ -180,7 +180,6 @@ frame_benchmarking::benchmarks! { // NOTE: this benchmark currently doesn't have any components because the length of a db // read/write is not captured. Otherwise, it is quite influenced by how much data // `T::ElectionDataProvider` is reading and passing on. - // TODO well it is about time to change this. assert!(>::snapshot().is_none()); assert!(>::current_phase().is_off()); }: {