mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-05-31 01:41:03 +00:00
Add benchmarking for parachain runtime paras pallet (#3888)
* Crate basic barebones benchmarking infrastructure for paras * Fill in benchmarking contents * cargo run --quiet --release --features=runtime-benchmarks -- benchmark --chain=westend-dev --steps=50 --repeat=20 --pallet=runtime_parachains::paras --extrinsic=* --execution=wasm --wasm-execution=compiled --heap-pages=4096 --header=./file_header.txt --output=./runtime/westend/src/weights/runtime_parachains_paras.rs * cargo run --quiet --release --features=runtime-benchmarks -- benchmark --chain=kusama-dev --steps=50 --repeat=20 --pallet=runtime_parachains::paras --extrinsic=* --execution=wasm --wasm-execution=compiled --heap-pages=4096 --header=./file_header.txt --output=./runtime/kusama/src/weights/runtime_parachains_paras.rs * Use autogenerated WeightInfos for kusama and westend * cargo fmt * Use saturating_sub * Add missing import * Try and hit the worst possible time complexity as much as possible * cargo fmt * cargo run --quiet --release --features=runtime-benchmarks -- benchmark --chain=westend-dev --steps=50 --repeat=20 --pallet=runtime_parachains::paras --extrinsic=* --execution=wasm --wasm-execution=compiled --heap-pages=4096 --header=./file_header.txt --output=./runtime/westend/src/weights/runtime_parachains_paras.rs * cargo run --quiet --release --features=runtime-benchmarks -- benchmark --chain=kusama-dev --steps=50 --repeat=20 --pallet=runtime_parachains::paras --extrinsic=* --execution=wasm --wasm-execution=compiled --heap-pages=4096 --header=./file_header.txt --output=./runtime/kusama/src/weights/runtime_parachains_paras.rs * Add a MAX_HEAD_DATA_SIZE constant * Prefill vectors with sample data for worst case complexity * cargo run --quiet --release --features=runtime-benchmarks -- benchmark --chain=westend-dev --steps=50 --repeat=20 --pallet=runtime_parachains::paras --extrinsic=* --execution=wasm --wasm-execution=compiled --heap-pages=4096 --header=./file_header.txt --output=./runtime/westend/src/weights/runtime_parachains_paras.rs * cargo run --quiet --release --features=runtime-benchmarks -- benchmark --chain=kusama-dev --steps=50 --repeat=20 --pallet=runtime_parachains::paras --extrinsic=* --execution=wasm --wasm-execution=compiled --heap-pages=4096 --header=./file_header.txt --output=./runtime/kusama/src/weights/runtime_parachains_paras.rs * Improve comment on SAMPLE_SIZE constant Co-authored-by: Parity Bot <admin@parity.io>
This commit is contained in:
@@ -0,0 +1,135 @@
|
||||
// Copyright 2021 Parity Technologies (UK) Ltd.
|
||||
// This file is part of Polkadot.
|
||||
|
||||
// Polkadot is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
|
||||
// Polkadot is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with Polkadot. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
use super::*;
|
||||
use crate::{configuration::HostConfiguration, shared};
|
||||
use frame_benchmarking::{benchmarks, impl_benchmark_test_suite};
|
||||
use frame_system::RawOrigin;
|
||||
use primitives::v1::{HeadData, Id as ParaId, ValidationCode, MAX_CODE_SIZE, MAX_HEAD_DATA_SIZE};
|
||||
use sp_runtime::traits::{One, Saturating};
|
||||
|
||||
// 2 ^ 10, because binary search time complexity is O(log(2, n)) and n = 1024 gives us a big and
|
||||
// round number.
|
||||
// Due to the limited number of parachains, the number of pruning, upcoming upgrades and cooldowns
|
||||
// shouldn't exceed this number.
|
||||
const SAMPLE_SIZE: u32 = 1024;
|
||||
|
||||
fn assert_last_event<T: Config>(generic_event: <T as Config>::Event) {
|
||||
let events = frame_system::Pallet::<T>::events();
|
||||
let system_event: <T as frame_system::Config>::Event = generic_event.into();
|
||||
// compare to the last event record
|
||||
let frame_system::EventRecord { event, .. } = &events[events.len() - 1];
|
||||
assert_eq!(event, &system_event);
|
||||
}
|
||||
|
||||
fn generate_disordered_pruning<T: Config>() {
|
||||
let mut needs_pruning = Vec::new();
|
||||
|
||||
for i in 0..SAMPLE_SIZE {
|
||||
let id = ParaId::from(i);
|
||||
let block_number = T::BlockNumber::from(1000u32);
|
||||
needs_pruning.push((id, block_number));
|
||||
}
|
||||
|
||||
<Pallet<T> as Store>::PastCodePruning::put(needs_pruning);
|
||||
}
|
||||
|
||||
fn generate_disordered_upgrades<T: Config>() {
|
||||
let mut upgrades = Vec::new();
|
||||
let mut cooldowns = Vec::new();
|
||||
|
||||
for i in 0..SAMPLE_SIZE {
|
||||
let id = ParaId::from(i);
|
||||
let block_number = T::BlockNumber::from(1000u32);
|
||||
upgrades.push((id, block_number));
|
||||
cooldowns.push((id, block_number));
|
||||
}
|
||||
|
||||
<Pallet<T> as Store>::UpcomingUpgrades::put(upgrades);
|
||||
<Pallet<T> as Store>::UpgradeCooldowns::put(cooldowns);
|
||||
}
|
||||
|
||||
fn generate_disordered_actions_queue<T: Config>() {
|
||||
let mut queue = Vec::new();
|
||||
let next_session = shared::Pallet::<T>::session_index().saturating_add(One::one());
|
||||
|
||||
for _ in 0..SAMPLE_SIZE {
|
||||
let id = ParaId::from(1000);
|
||||
queue.push(id);
|
||||
}
|
||||
|
||||
<Pallet<T> as Store>::ActionsQueue::mutate(next_session, |v| {
|
||||
*v = queue;
|
||||
});
|
||||
}
|
||||
|
||||
benchmarks! {
|
||||
force_set_current_code {
|
||||
let c in 1 .. MAX_CODE_SIZE;
|
||||
let new_code = ValidationCode(vec![0; c as usize]);
|
||||
let para_id = ParaId::from(c as u32);
|
||||
generate_disordered_pruning::<T>();
|
||||
}: _(RawOrigin::Root, para_id, new_code)
|
||||
verify {
|
||||
assert_last_event::<T>(Event::CurrentCodeUpdated(para_id).into());
|
||||
}
|
||||
force_set_current_head {
|
||||
let s in 1 .. MAX_HEAD_DATA_SIZE;
|
||||
let new_head = HeadData(vec![0; s as usize]);
|
||||
let para_id = ParaId::from(1000);
|
||||
}: _(RawOrigin::Root, para_id, new_head)
|
||||
verify {
|
||||
assert_last_event::<T>(Event::CurrentHeadUpdated(para_id).into());
|
||||
}
|
||||
force_schedule_code_upgrade {
|
||||
let c in 1 .. MAX_CODE_SIZE;
|
||||
let new_code = ValidationCode(vec![0; c as usize]);
|
||||
let para_id = ParaId::from(c as u32);
|
||||
let block = T::BlockNumber::from(c);
|
||||
generate_disordered_upgrades::<T>();
|
||||
}: _(RawOrigin::Root, para_id, new_code, block)
|
||||
verify {
|
||||
assert_last_event::<T>(Event::CodeUpgradeScheduled(para_id).into());
|
||||
}
|
||||
force_note_new_head {
|
||||
let s in 1 .. MAX_HEAD_DATA_SIZE;
|
||||
let para_id = ParaId::from(1000);
|
||||
let new_head = HeadData(vec![0; s as usize]);
|
||||
// schedule an expired code upgrade for this para_id so that force_note_new_head would use
|
||||
// the worst possible code path
|
||||
let expired = frame_system::Pallet::<T>::block_number().saturating_sub(One::one());
|
||||
let config = HostConfiguration::<T::BlockNumber>::default();
|
||||
generate_disordered_pruning::<T>();
|
||||
Pallet::<T>::schedule_code_upgrade(para_id, ValidationCode(vec![0]), expired, &config);
|
||||
}: _(RawOrigin::Root, para_id, new_head)
|
||||
verify {
|
||||
assert_last_event::<T>(Event::NewHeadNoted(para_id).into());
|
||||
}
|
||||
force_queue_action {
|
||||
let para_id = ParaId::from(1000);
|
||||
generate_disordered_actions_queue::<T>();
|
||||
}: _(RawOrigin::Root, para_id)
|
||||
verify {
|
||||
let next_session = crate::shared::Pallet::<T>::session_index().saturating_add(One::one());
|
||||
assert_last_event::<T>(Event::ActionQueued(para_id, next_session).into());
|
||||
}
|
||||
}
|
||||
|
||||
impl_benchmark_test_suite!(
|
||||
Pallet,
|
||||
crate::mock::new_test_ext(Default::default()),
|
||||
crate::mock::Test
|
||||
);
|
||||
@@ -0,0 +1,97 @@
|
||||
|
||||
//! Autogenerated weights for `runtime_parachains::paras`
|
||||
//!
|
||||
//! THIS FILE WAS AUTO-GENERATED USING THE SUBSTRATE BENCHMARK CLI VERSION 4.0.0-dev
|
||||
//! DATE: 2021-09-21, STEPS: `50`, REPEAT: 20, LOW RANGE: `[]`, HIGH RANGE: `[]`
|
||||
//! EXECUTION: Some(Wasm), WASM-EXECUTION: Compiled, CHAIN: Some("westend-dev"), DB CACHE: 128
|
||||
|
||||
// Executed Command:
|
||||
// ./target/release/polkadot
|
||||
// benchmark
|
||||
// --chain
|
||||
// westend-dev
|
||||
// --execution=wasm
|
||||
// --wasm-execution=compiled
|
||||
// --pallet
|
||||
// runtime_parachains::paras
|
||||
// --steps
|
||||
// 50
|
||||
// --repeat
|
||||
// 20
|
||||
// --raw
|
||||
// --extrinsic
|
||||
// *
|
||||
// --output
|
||||
// runtime/parachains/src/paras/weights.rs
|
||||
|
||||
|
||||
#![cfg_attr(rustfmt, rustfmt_skip)]
|
||||
#![allow(unused_parens)]
|
||||
#![allow(unused_imports)]
|
||||
|
||||
use frame_support::{traits::Get, weights::Weight};
|
||||
use sp_std::marker::PhantomData;
|
||||
|
||||
/// Weight functions for `runtime_parachains::paras`.
|
||||
pub struct WeightInfo<T>(PhantomData<T>);
|
||||
impl<T: frame_system::Config> super::WeightInfo for WeightInfo<T> {
|
||||
// Storage: Paras CurrentCodeHash (r:1 w:1)
|
||||
// Storage: Paras CodeByHashRefs (r:1 w:1)
|
||||
// Storage: Paras PastCodeMeta (r:1 w:1)
|
||||
// Storage: Paras PastCodePruning (r:1 w:1)
|
||||
// Storage: Paras PastCodeHash (r:0 w:1)
|
||||
// Storage: Paras CodeByHash (r:0 w:1)
|
||||
fn force_set_current_code(c: u32, ) -> Weight {
|
||||
(14_669_000 as Weight)
|
||||
// Standard Error: 0
|
||||
.saturating_add((3_000 as Weight).saturating_mul(c as Weight))
|
||||
.saturating_add(T::DbWeight::get().reads(4 as Weight))
|
||||
.saturating_add(T::DbWeight::get().writes(6 as Weight))
|
||||
}
|
||||
// Storage: Paras Heads (r:0 w:1)
|
||||
fn force_set_current_head(s: u32, ) -> Weight {
|
||||
(0 as Weight)
|
||||
// Standard Error: 0
|
||||
.saturating_add((2_000 as Weight).saturating_mul(s as Weight))
|
||||
.saturating_add(T::DbWeight::get().writes(1 as Weight))
|
||||
}
|
||||
// Storage: Configuration ActiveConfig (r:1 w:0)
|
||||
// Storage: Paras FutureCodeUpgrades (r:1 w:1)
|
||||
// Storage: Paras UpcomingUpgrades (r:1 w:1)
|
||||
// Storage: Paras UpgradeCooldowns (r:1 w:1)
|
||||
// Storage: System Digest (r:1 w:1)
|
||||
// Storage: Paras CodeByHashRefs (r:1 w:1)
|
||||
// Storage: Paras CodeByHash (r:0 w:1)
|
||||
// Storage: Paras FutureCodeHash (r:0 w:1)
|
||||
// Storage: Paras UpgradeRestrictionSignal (r:0 w:1)
|
||||
fn force_schedule_code_upgrade(c: u32, ) -> Weight {
|
||||
(37_383_000 as Weight)
|
||||
// Standard Error: 0
|
||||
.saturating_add((3_000 as Weight).saturating_mul(c as Weight))
|
||||
.saturating_add(T::DbWeight::get().reads(6 as Weight))
|
||||
.saturating_add(T::DbWeight::get().writes(8 as Weight))
|
||||
}
|
||||
// Storage: Paras FutureCodeUpgrades (r:1 w:1)
|
||||
// Storage: Paras FutureCodeHash (r:1 w:1)
|
||||
// Storage: Paras CurrentCodeHash (r:1 w:1)
|
||||
// Storage: System Digest (r:1 w:1)
|
||||
// Storage: Paras PastCodeMeta (r:1 w:1)
|
||||
// Storage: Paras PastCodePruning (r:1 w:1)
|
||||
// Storage: Paras Heads (r:0 w:1)
|
||||
// Storage: Paras PastCodeHash (r:0 w:1)
|
||||
// Storage: Paras UpgradeGoAheadSignal (r:0 w:1)
|
||||
fn force_note_new_head(s: u32, ) -> Weight {
|
||||
(60_855_000 as Weight)
|
||||
// Standard Error: 0
|
||||
.saturating_add((2_000 as Weight).saturating_mul(s as Weight))
|
||||
.saturating_add(T::DbWeight::get().reads(6 as Weight))
|
||||
.saturating_add(T::DbWeight::get().writes(9 as Weight))
|
||||
}
|
||||
// Storage: ParasShared CurrentSessionIndex (r:1 w:0)
|
||||
// Storage: Paras ActionsQueue (r:1 w:1)
|
||||
fn force_queue_action() -> Weight {
|
||||
(32_014_000 as Weight)
|
||||
.saturating_add(T::DbWeight::get().reads(2 as Weight))
|
||||
.saturating_add(T::DbWeight::get().writes(1 as Weight))
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user