Skip to content
This repository has been archived by the owner on Nov 15, 2023. It is now read-only.

Commit

Permalink
Refactors election provider support benchmarks outside its own crate (#…
Browse files Browse the repository at this point in the history
…13431)

* Refactors election provider support benchmarks outside its own crate
---------

Co-authored-by: command-bot <>
  • Loading branch information
gpestana authored Feb 22, 2023
1 parent 281f7b8 commit 70ea87a
Show file tree
Hide file tree
Showing 11 changed files with 194 additions and 253 deletions.
258 changes: 121 additions & 137 deletions Cargo.lock

Large diffs are not rendered by default.

1 change: 0 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,6 @@ members = [
"frame/elections",
"frame/election-provider-multi-phase",
"frame/election-provider-support",
"frame/election-provider-support/benchmarking",
"frame/election-provider-support/solution-type",
"frame/election-provider-support/solution-type/fuzzer",
"frame/examples/basic",
Expand Down
4 changes: 1 addition & 3 deletions bin/node/runtime/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,6 @@ pallet-contracts-primitives = { version = "7.0.0", default-features = false, pat
pallet-conviction-voting = { version = "4.0.0-dev", default-features = false, path = "../../../frame/conviction-voting" }
pallet-democracy = { version = "4.0.0-dev", default-features = false, path = "../../../frame/democracy" }
pallet-election-provider-multi-phase = { version = "4.0.0-dev", default-features = false, path = "../../../frame/election-provider-multi-phase" }
pallet-election-provider-support-benchmarking = { version = "4.0.0-dev", default-features = false, path = "../../../frame/election-provider-support/benchmarking", optional = true }
pallet-elections = { version = "5.0.0-dev", default-features = false, path = "../../../frame/elections" }
pallet-fast-unstake = { version = "4.0.0-dev", default-features = false, path = "../../../frame/fast-unstake" }
pallet-nis = { version = "4.0.0-dev", default-features = false, path = "../../../frame/nis" }
Expand Down Expand Up @@ -124,7 +123,6 @@ with-tracing = ["frame-executive/with-tracing"]
std = [
"pallet-whitelist/std",
"pallet-offences-benchmarking?/std",
"pallet-election-provider-support-benchmarking?/std",
"pallet-asset-tx-payment/std",
"frame-system-benchmarking?/std",
"frame-election-provider-support/std",
Expand Down Expand Up @@ -218,6 +216,7 @@ runtime-benchmarks = [
"frame-benchmarking-pallet-pov/runtime-benchmarks",
"frame-support/runtime-benchmarks",
"frame-system/runtime-benchmarks",
"frame-election-provider-support/runtime-benchmarks",
"sp-runtime/runtime-benchmarks",
"pallet-alliance/runtime-benchmarks",
"pallet-assets/runtime-benchmarks",
Expand All @@ -231,7 +230,6 @@ runtime-benchmarks = [
"pallet-conviction-voting/runtime-benchmarks",
"pallet-democracy/runtime-benchmarks",
"pallet-election-provider-multi-phase/runtime-benchmarks",
"pallet-election-provider-support-benchmarking/runtime-benchmarks",
"pallet-elections/runtime-benchmarks",
"pallet-fast-unstake/runtime-benchmarks",
"pallet-nis/runtime-benchmarks",
Expand Down
8 changes: 4 additions & 4 deletions bin/node/runtime/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1857,6 +1857,7 @@ mod benches {
frame_benchmarking::define_benchmarks!(
[frame_benchmarking, BaselineBench::<Runtime>]
[frame_benchmarking_pallet_pov, Pov]
[frame_election_provider_support, EPSBench::<Runtime>]
[pallet_alliance, Alliance]
[pallet_assets, Assets]
[pallet_babe, Babe]
Expand All @@ -1869,7 +1870,6 @@ mod benches {
[pallet_contracts, Contracts]
[pallet_democracy, Democracy]
[pallet_election_provider_multi_phase, ElectionProviderMultiPhase]
[pallet_election_provider_support_benchmarking, EPSBench::<Runtime>]
[pallet_elections, Elections]
[pallet_fast_unstake, FastUnstake]
[pallet_nis, Nis]
Expand Down Expand Up @@ -2285,7 +2285,7 @@ impl_runtime_apis! {
// which is why we need these two lines below.
use pallet_session_benchmarking::Pallet as SessionBench;
use pallet_offences_benchmarking::Pallet as OffencesBench;
use pallet_election_provider_support_benchmarking::Pallet as EPSBench;
use frame_election_provider_support::benchmarking::Pallet as EPSBench;
use frame_system_benchmarking::Pallet as SystemBench;
use baseline::Pallet as BaselineBench;
use pallet_nomination_pools_benchmarking::Pallet as NominationPoolsBench;
Expand All @@ -2308,14 +2308,14 @@ impl_runtime_apis! {
// which is why we need these two lines below.
use pallet_session_benchmarking::Pallet as SessionBench;
use pallet_offences_benchmarking::Pallet as OffencesBench;
use pallet_election_provider_support_benchmarking::Pallet as EPSBench;
use frame_election_provider_support::benchmarking::Pallet as EPSBench;
use frame_system_benchmarking::Pallet as SystemBench;
use baseline::Pallet as BaselineBench;
use pallet_nomination_pools_benchmarking::Pallet as NominationPoolsBench;

impl pallet_session_benchmarking::Config for Runtime {}
impl pallet_offences_benchmarking::Config for Runtime {}
impl pallet_election_provider_support_benchmarking::Config for Runtime {}
impl frame_election_provider_support::benchmarking::Config for Runtime {}
impl frame_system_benchmarking::Config for Runtime {}
impl baseline::Config for Runtime {}
impl pallet_nomination_pools_benchmarking::Config for Runtime {}
Expand Down
2 changes: 0 additions & 2 deletions frame/election-provider-multi-phase/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ frame-election-provider-support = { version = "4.0.0-dev", default-features = fa

# Optional imports for benchmarking
frame-benchmarking = { version = "4.0.0-dev", default-features = false, path = "../benchmarking", optional = true }
pallet-election-provider-support-benchmarking = { version = "4.0.0-dev", default-features = false, path = "../election-provider-support/benchmarking", optional = true }
rand = { version = "0.8.5", default-features = false, features = ["alloc", "small_rng"], optional = true }
strum = { version = "0.24.1", default-features = false, features = ["derive"], optional = true }

Expand All @@ -50,7 +49,6 @@ frame-benchmarking = { version = "4.0.0-dev", path = "../benchmarking" }
[features]
default = ["std"]
std = [
"pallet-election-provider-support-benchmarking?/std",
"codec/std",
"scale-info/std",
"log/std",
Expand Down
8 changes: 7 additions & 1 deletion frame/election-provider-support/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ sp-runtime = { version = "7.0.0", default-features = false, path = "../../primit
sp-std = { version = "5.0.0", default-features = false, path = "../../primitives/std" }
sp-core = { version = "7.0.0", default-features = false, path = "../../primitives/core" }

frame-benchmarking = { version = "4.0.0-dev", default-features = false, path = "../benchmarking", optional = true }

[dev-dependencies]
rand = { version = "0.8.5", features = ["small_rng"] }
sp-io = { version = "7.0.0", path = "../../primitives/io" }
Expand All @@ -41,6 +43,10 @@ std = [
"sp-core/std",
"sp-runtime/std",
"sp-std/std",

"frame-benchmarking?/std",
]
runtime-benchmarks = [
"frame-benchmarking/runtime-benchmarks",
]
runtime-benchmarks = []
try-runtime = []
37 changes: 0 additions & 37 deletions frame/election-provider-support/benchmarking/Cargo.toml

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,9 @@
//! Election provider support pallet benchmarking.
//! This is separated into its own crate to avoid bloating the size of the runtime.
#![cfg(feature = "runtime-benchmarks")]
#![cfg_attr(not(feature = "std"), no_std)]

use crate::{ApprovalVoting, NposSolver, PhragMMS, SequentialPhragmen};
use codec::Decode;
use frame_benchmarking::v1::{benchmarks, Vec};
use frame_election_provider_support::{ApprovalVoting, NposSolver, PhragMMS, SequentialPhragmen};

pub struct Pallet<T: Config>(frame_system::Pallet<T>);
pub trait Config: frame_system::Config {}
Expand Down
3 changes: 3 additions & 0 deletions frame/election-provider-support/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,9 @@ pub use sp_arithmetic;
#[doc(hidden)]
pub use sp_std;

#[cfg(feature = "runtime-benchmarks")]
pub mod benchmarking;

pub mod weights;
pub use weights::WeightInfo;

Expand Down
119 changes: 57 additions & 62 deletions frame/election-provider-support/src/weights.rs
Original file line number Diff line number Diff line change
@@ -1,49 +1,44 @@
// This file is part of Substrate.

// Copyright (C) Parity Technologies (UK) Ltd.
// Copyright (C) 2023 Parity Technologies (UK) Ltd.
// SPDX-License-Identifier: Apache-2.0

// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

//! Autogenerated weights for pallet_election_provider_support_benchmarking
//! Autogenerated weights for frame_election_provider_support
//!
//! THIS FILE WAS AUTO-GENERATED USING THE SUBSTRATE BENCHMARK CLI VERSION 4.0.0-dev
//! DATE: 2023-02-20, STEPS: `50`, REPEAT: `20`, LOW RANGE: `[]`, HIGH RANGE: `[]`
//! DATE: 2023-02-22, STEPS: `50`, REPEAT: `20`, LOW RANGE: `[]`, HIGH RANGE: `[]`
//! WORST CASE MAP SIZE: `1000000`
//! HOSTNAME: `Rosss-MacBook-Pro-2.local`, CPU: `<UNKNOWN>`
//! EXECUTION: Some(Wasm), WASM-EXECUTION: Compiled, CHAIN: None, DB CACHE: 1024
//! HOSTNAME: `runner-ehxwxxsd-project-145-concurrent-0`, CPU: `Intel(R) Xeon(R) CPU @ 2.60GHz`
//! EXECUTION: Some(Wasm), WASM-EXECUTION: Compiled, CHAIN: Some("dev"), DB CACHE: 1024
// Executed Command:
// target/release/substrate
// target/production/substrate
// benchmark
// pallet
// --execution
// wasm
// --wasm-execution
// compiled
// --dev
// --pallet
// pallet-election-provider-support-benchmarking
// --extrinsic
// *
// --steps
// 50
// --repeat
// 20
// --output
// frame/election-provider-support/src/weights.rs
// --template
// .maintain/frame-weight-template.hbs
// --steps=50
// --repeat=20
// --extrinsic=*
// --execution=wasm
// --wasm-execution=compiled
// --heap-pages=4096
// --json-file=/builds/parity/mirrors/substrate/.git/.artifacts/bench.json
// --pallet=frame_election_provider_support
// --chain=dev
// --header=./HEADER-APACHE2
// --output=./frame/election-provider-support/src/weights.rs
// --template=./.maintain/frame-weight-template.hbs

#![cfg_attr(rustfmt, rustfmt_skip)]
#![allow(unused_parens)]
Expand All @@ -52,14 +47,14 @@
use frame_support::{traits::Get, weights::{Weight, constants::RocksDbWeight}};
use sp_std::marker::PhantomData;

/// Weight functions needed for pallet_election_provider_support_benchmarking.
/// Weight functions needed for frame_election_provider_support.
pub trait WeightInfo {
fn phragmen(v: u32, t: u32, d: u32, ) -> Weight;
fn phragmms(v: u32, t: u32, d: u32, ) -> Weight;
fn approval_voting(v: u32, t: u32, d: u32, ) -> Weight;
}

/// Weights for pallet_election_provider_support_benchmarking using the Substrate node and recommended hardware.
/// Weights for frame_election_provider_support using the Substrate node and recommended hardware.
pub struct SubstrateWeight<T>(PhantomData<T>);
impl<T: frame_system::Config> WeightInfo for SubstrateWeight<T> {
/// The range of component `v` is `[1000, 2000]`.
Expand All @@ -69,13 +64,13 @@ impl<T: frame_system::Config> WeightInfo for SubstrateWeight<T> {
// Proof Size summary in bytes:
// Measured: `0`
// Estimated: `0`
// Minimum execution time: 5_215_000 nanoseconds.
Weight::from_ref_time(5_325_000_000)
// Minimum execution time: 5_789_174 nanoseconds.
Weight::from_ref_time(5_826_449_000)
.saturating_add(Weight::from_proof_size(0))
// Standard Error: 106_262
.saturating_add(Weight::from_ref_time(3_989_100).saturating_mul(v.into()))
// Standard Error: 10_863_902
.saturating_add(Weight::from_ref_time(1_008_030_786).saturating_mul(d.into()))
// Standard Error: 130_342
.saturating_add(Weight::from_ref_time(5_332_741).saturating_mul(v.into()))
// Standard Error: 13_325_769
.saturating_add(Weight::from_ref_time(1_416_874_101).saturating_mul(d.into()))
}
/// The range of component `v` is `[1000, 2000]`.
/// The range of component `t` is `[500, 1000]`.
Expand All @@ -84,13 +79,13 @@ impl<T: frame_system::Config> WeightInfo for SubstrateWeight<T> {
// Proof Size summary in bytes:
// Measured: `0`
// Estimated: `0`
// Minimum execution time: 3_703_000 nanoseconds.
Weight::from_ref_time(3_715_000_000)
// Minimum execution time: 4_151_790 nanoseconds.
Weight::from_ref_time(4_215_936_000)
.saturating_add(Weight::from_proof_size(0))
// Standard Error: 85_871
.saturating_add(Weight::from_ref_time(3_443_928).saturating_mul(v.into()))
// Standard Error: 8_779_237
.saturating_add(Weight::from_ref_time(985_037_659).saturating_mul(d.into()))
// Standard Error: 125_135
.saturating_add(Weight::from_ref_time(4_730_609).saturating_mul(v.into()))
// Standard Error: 12_793_390
.saturating_add(Weight::from_ref_time(1_474_383_961).saturating_mul(d.into()))
}
/// The range of component `v` is `[1000, 2000]`.
/// The range of component `t` is `[500, 1000]`.
Expand All @@ -99,13 +94,13 @@ impl<T: frame_system::Config> WeightInfo for SubstrateWeight<T> {
// Proof Size summary in bytes:
// Measured: `0`
// Estimated: `0`
// Minimum execution time: 1_863_000 nanoseconds.
Weight::from_ref_time(1_868_000_000)
// Minimum execution time: 1_800_445 nanoseconds.
Weight::from_ref_time(1_824_645_000)
.saturating_add(Weight::from_proof_size(0))
// Standard Error: 24_930
.saturating_add(Weight::from_ref_time(1_215_357).saturating_mul(v.into()))
// Standard Error: 2_548_811
.saturating_add(Weight::from_ref_time(197_537_394).saturating_mul(d.into()))
// Standard Error: 26_266
.saturating_add(Weight::from_ref_time(1_229_576).saturating_mul(v.into()))
// Standard Error: 2_685_343
.saturating_add(Weight::from_ref_time(213_080_804).saturating_mul(d.into()))
}
}

Expand All @@ -118,13 +113,13 @@ impl WeightInfo for () {
// Proof Size summary in bytes:
// Measured: `0`
// Estimated: `0`
// Minimum execution time: 5_215_000 nanoseconds.
Weight::from_ref_time(5_325_000_000)
// Minimum execution time: 5_789_174 nanoseconds.
Weight::from_ref_time(5_826_449_000)
.saturating_add(Weight::from_proof_size(0))
// Standard Error: 106_262
.saturating_add(Weight::from_ref_time(3_989_100).saturating_mul(v.into()))
// Standard Error: 10_863_902
.saturating_add(Weight::from_ref_time(1_008_030_786).saturating_mul(d.into()))
// Standard Error: 130_342
.saturating_add(Weight::from_ref_time(5_332_741).saturating_mul(v.into()))
// Standard Error: 13_325_769
.saturating_add(Weight::from_ref_time(1_416_874_101).saturating_mul(d.into()))
}
/// The range of component `v` is `[1000, 2000]`.
/// The range of component `t` is `[500, 1000]`.
Expand All @@ -133,13 +128,13 @@ impl WeightInfo for () {
// Proof Size summary in bytes:
// Measured: `0`
// Estimated: `0`
// Minimum execution time: 3_703_000 nanoseconds.
Weight::from_ref_time(3_715_000_000)
// Minimum execution time: 4_151_790 nanoseconds.
Weight::from_ref_time(4_215_936_000)
.saturating_add(Weight::from_proof_size(0))
// Standard Error: 85_871
.saturating_add(Weight::from_ref_time(3_443_928).saturating_mul(v.into()))
// Standard Error: 8_779_237
.saturating_add(Weight::from_ref_time(985_037_659).saturating_mul(d.into()))
// Standard Error: 125_135
.saturating_add(Weight::from_ref_time(4_730_609).saturating_mul(v.into()))
// Standard Error: 12_793_390
.saturating_add(Weight::from_ref_time(1_474_383_961).saturating_mul(d.into()))
}
/// The range of component `v` is `[1000, 2000]`.
/// The range of component `t` is `[500, 1000]`.
Expand All @@ -148,12 +143,12 @@ impl WeightInfo for () {
// Proof Size summary in bytes:
// Measured: `0`
// Estimated: `0`
// Minimum execution time: 1_863_000 nanoseconds.
Weight::from_ref_time(1_868_000_000)
// Minimum execution time: 1_800_445 nanoseconds.
Weight::from_ref_time(1_824_645_000)
.saturating_add(Weight::from_proof_size(0))
// Standard Error: 24_930
.saturating_add(Weight::from_ref_time(1_215_357).saturating_mul(v.into()))
// Standard Error: 2_548_811
.saturating_add(Weight::from_ref_time(197_537_394).saturating_mul(d.into()))
// Standard Error: 26_266
.saturating_add(Weight::from_ref_time(1_229_576).saturating_mul(v.into()))
// Standard Error: 2_685_343
.saturating_add(Weight::from_ref_time(213_080_804).saturating_mul(d.into()))
}
}
2 changes: 0 additions & 2 deletions scripts/run_all_benchmarks.sh
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,6 @@ SUBSTRATE=./target/production/substrate

# Manually exclude some pallets.
EXCLUDED_PALLETS=(
# Helper pallets
"pallet_election_provider_support_benchmarking"
# Pallets without automatic benchmarking
"pallet_babe"
"pallet_grandpa"
Expand Down

0 comments on commit 70ea87a

Please sign in to comment.