Adds ability to prepare/initialize before running set_code benchmark (#14435)

* Adds ability to prepare/initialize before running `set_code` benchmark

* Fix

* ".git/.scripts/commands/bench/bench.sh" pallet dev frame-system

* Replaced BenchmarkHelper with function

* Fix

* Introduced `set_code_data` for benchmark with default value

* ".git/.scripts/commands/bench/bench.sh" pallet dev frame-system

* (Hope) Final adjustment (because system parachains generates ValidationFunctionStored instead of CodeUpdated)

* ".git/.scripts/commands/bench/bench.sh" pallet dev frame-system

* ".git/.scripts/commands/bench-vm/bench-vm.sh" pallet dev frame-system

---------

Co-authored-by: command-bot <>
This commit is contained in:
Branislav Kontur
2023-06-23 14:02:13 +02:00
committed by GitHub
parent 7d4fd6a442
commit 3e2c73dfad
2 changed files with 81 additions and 59 deletions
+28 -4
View File
@@ -20,7 +20,10 @@
#![cfg_attr(not(feature = "std"), no_std)]
use codec::Encode;
use frame_benchmarking::v1::{benchmarks, whitelisted_caller};
use frame_benchmarking::{
v1::{benchmarks, whitelisted_caller},
BenchmarkError,
};
use frame_support::{dispatch::DispatchClass, storage, traits::Get};
use frame_system::{Call, Pallet as System, RawOrigin};
use sp_core::storage::well_known_keys;
@@ -30,7 +33,26 @@ use sp_std::{prelude::*, vec};
mod mock;
pub struct Pallet<T: Config>(System<T>);
pub trait Config: frame_system::Config {}
pub trait Config: frame_system::Config {
/// Adds ability to the Runtime to test against their sample code.
///
/// Default is `../res/kitchensink_runtime.compact.compressed.wasm`.
fn prepare_set_code_data() -> Vec<u8> {
include_bytes!("../res/kitchensink_runtime.compact.compressed.wasm").to_vec()
}
/// Adds ability to the Runtime to prepare/initialize before running benchmark `set_code`.
fn setup_set_code_requirements(_code: &Vec<u8>) -> Result<(), BenchmarkError> {
Ok(())
}
/// Adds ability to the Runtime to do custom validation after benchmark.
///
/// Default is checking for `CodeUpdated` event .
fn verify_set_code() {
System::<Self>::assert_last_event(frame_system::Event::<Self>::CodeUpdated.into());
}
}
benchmarks! {
remark {
@@ -49,16 +71,18 @@ benchmarks! {
}: _(RawOrigin::Root, Default::default())
set_code {
let runtime_blob = include_bytes!("../res/kitchensink_runtime.compact.compressed.wasm").to_vec();
let runtime_blob = T::prepare_set_code_data();
T::setup_set_code_requirements(&runtime_blob)?;
}: _(RawOrigin::Root, runtime_blob)
verify {
System::<T>::assert_last_event(frame_system::Event::<T>::CodeUpdated.into());
T::verify_set_code()
}
#[extra]
set_code_without_checks {
// Assume Wasm ~4MB
let code = vec![1; 4_000_000 as usize];
T::setup_set_code_requirements(&code)?;
}: _(RawOrigin::Root, code)
verify {
let current_code = storage::unhashed::get_raw(well_known_keys::CODE).ok_or("Code not stored.")?;
+53 -55
View File
@@ -18,28 +18,26 @@
//! Autogenerated weights for frame_system
//!
//! THIS FILE WAS AUTO-GENERATED USING THE SUBSTRATE BENCHMARK CLI VERSION 4.0.0-dev
//! DATE: 2023-06-16, STEPS: `50`, REPEAT: `20`, LOW RANGE: `[]`, HIGH RANGE: `[]`
//! DATE: 2023-06-22, STEPS: `50`, REPEAT: `20`, LOW RANGE: `[]`, HIGH RANGE: `[]`
//! WORST CASE MAP SIZE: `1000000`
//! HOSTNAME: `runner-e8ezs4ez-project-145-concurrent-0`, CPU: `Intel(R) Xeon(R) CPU @ 2.60GHz`
//! HOSTNAME: `runner-s7kdgajz-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/production/substrate
// target/production/substrate
// benchmark
// pallet
// --chain=dev
// --steps=50
// --repeat=20
// --pallet=frame_system
// --no-storage-info
// --no-median-slopes
// --no-min-squares
// --extrinsic=*
// --execution=wasm
// --wasm-execution=compiled
// --heap-pages=4096
// --output=./frame/system/src/weights.rs
// --json-file=/builds/parity/mirrors/substrate/.git/.artifacts/bench.json
// --pallet=frame-system
// --chain=dev
// --header=./HEADER-APACHE2
// --output=./frame/system/src/weights.rs
// --template=./.maintain/frame-weight-template.hbs
#![cfg_attr(rustfmt, rustfmt_skip)]
@@ -69,20 +67,20 @@ impl<T: crate::Config> WeightInfo for SubstrateWeight<T> {
// Proof Size summary in bytes:
// Measured: `0`
// Estimated: `0`
// Minimum execution time: 2_037_000 picoseconds.
Weight::from_parts(2_118_000, 0)
// Minimum execution time: 2_004_000 picoseconds.
Weight::from_parts(2_119_000, 0)
// Standard Error: 0
.saturating_add(Weight::from_parts(386, 0).saturating_mul(b.into()))
.saturating_add(Weight::from_parts(390, 0).saturating_mul(b.into()))
}
/// The range of component `b` is `[0, 3932160]`.
fn remark_with_event(b: u32, ) -> Weight {
// Proof Size summary in bytes:
// Measured: `0`
// Estimated: `0`
// Minimum execution time: 7_828_000 picoseconds.
Weight::from_parts(5_872_198, 0)
// Standard Error: 1
.saturating_add(Weight::from_parts(1_384, 0).saturating_mul(b.into()))
// Minimum execution time: 8_032_000 picoseconds.
Weight::from_parts(8_097_000, 0)
// Standard Error: 2
.saturating_add(Weight::from_parts(1_455, 0).saturating_mul(b.into()))
}
/// Storage: System Digest (r:1 w:1)
/// Proof Skipped: System Digest (max_values: Some(1), max_size: None, mode: Measured)
@@ -92,8 +90,8 @@ impl<T: crate::Config> WeightInfo for SubstrateWeight<T> {
// Proof Size summary in bytes:
// Measured: `0`
// Estimated: `1485`
// Minimum execution time: 4_339_000 picoseconds.
Weight::from_parts(4_688_000, 1485)
// Minimum execution time: 4_446_000 picoseconds.
Weight::from_parts(4_782_000, 1485)
.saturating_add(T::DbWeight::get().reads(1_u64))
.saturating_add(T::DbWeight::get().writes(2_u64))
}
@@ -105,8 +103,8 @@ impl<T: crate::Config> WeightInfo for SubstrateWeight<T> {
// Proof Size summary in bytes:
// Measured: `0`
// Estimated: `1485`
// Minimum execution time: 82_624_498_000 picoseconds.
Weight::from_parts(83_553_373_000, 1485)
// Minimum execution time: 84_000_503_000 picoseconds.
Weight::from_parts(87_586_619_000, 1485)
.saturating_add(T::DbWeight::get().reads(1_u64))
.saturating_add(T::DbWeight::get().writes(2_u64))
}
@@ -117,10 +115,10 @@ impl<T: crate::Config> WeightInfo for SubstrateWeight<T> {
// Proof Size summary in bytes:
// Measured: `0`
// Estimated: `0`
// Minimum execution time: 2_097_000 picoseconds.
Weight::from_parts(2_213_000, 0)
// Standard Error: 711
.saturating_add(Weight::from_parts(817_161, 0).saturating_mul(i.into()))
// Minimum execution time: 2_086_000 picoseconds.
Weight::from_parts(2_175_000, 0)
// Standard Error: 1_056
.saturating_add(Weight::from_parts(841_511, 0).saturating_mul(i.into()))
.saturating_add(T::DbWeight::get().writes((1_u64).saturating_mul(i.into())))
}
/// Storage: Skipped Metadata (r:0 w:0)
@@ -130,10 +128,10 @@ impl<T: crate::Config> WeightInfo for SubstrateWeight<T> {
// Proof Size summary in bytes:
// Measured: `0`
// Estimated: `0`
// Minimum execution time: 2_061_000 picoseconds.
Weight::from_parts(2_207_000, 0)
// Standard Error: 887
.saturating_add(Weight::from_parts(616_055, 0).saturating_mul(i.into()))
// Minimum execution time: 2_000_000 picoseconds.
Weight::from_parts(2_255_000, 0)
// Standard Error: 1_425
.saturating_add(Weight::from_parts(662_473, 0).saturating_mul(i.into()))
.saturating_add(T::DbWeight::get().writes((1_u64).saturating_mul(i.into())))
}
/// Storage: Skipped Metadata (r:0 w:0)
@@ -143,10 +141,10 @@ impl<T: crate::Config> WeightInfo for SubstrateWeight<T> {
// Proof Size summary in bytes:
// Measured: `115 + p * (69 ±0)`
// Estimated: `128 + p * (70 ±0)`
// Minimum execution time: 3_857_000 picoseconds.
Weight::from_parts(4_094_000, 128)
// Standard Error: 1_935
.saturating_add(Weight::from_parts(1_342_833, 0).saturating_mul(p.into()))
// Minimum execution time: 4_189_000 picoseconds.
Weight::from_parts(4_270_000, 128)
// Standard Error: 2_296
.saturating_add(Weight::from_parts(1_389_650, 0).saturating_mul(p.into()))
.saturating_add(T::DbWeight::get().reads((1_u64).saturating_mul(p.into())))
.saturating_add(T::DbWeight::get().writes((1_u64).saturating_mul(p.into())))
.saturating_add(Weight::from_parts(0, 70).saturating_mul(p.into()))
@@ -160,20 +158,20 @@ impl WeightInfo for () {
// Proof Size summary in bytes:
// Measured: `0`
// Estimated: `0`
// Minimum execution time: 2_037_000 picoseconds.
Weight::from_parts(2_118_000, 0)
// Minimum execution time: 2_004_000 picoseconds.
Weight::from_parts(2_119_000, 0)
// Standard Error: 0
.saturating_add(Weight::from_parts(386, 0).saturating_mul(b.into()))
.saturating_add(Weight::from_parts(390, 0).saturating_mul(b.into()))
}
/// The range of component `b` is `[0, 3932160]`.
fn remark_with_event(b: u32, ) -> Weight {
// Proof Size summary in bytes:
// Measured: `0`
// Estimated: `0`
// Minimum execution time: 7_828_000 picoseconds.
Weight::from_parts(5_872_198, 0)
// Standard Error: 1
.saturating_add(Weight::from_parts(1_384, 0).saturating_mul(b.into()))
// Minimum execution time: 8_032_000 picoseconds.
Weight::from_parts(8_097_000, 0)
// Standard Error: 2
.saturating_add(Weight::from_parts(1_455, 0).saturating_mul(b.into()))
}
/// Storage: System Digest (r:1 w:1)
/// Proof Skipped: System Digest (max_values: Some(1), max_size: None, mode: Measured)
@@ -183,8 +181,8 @@ impl WeightInfo for () {
// Proof Size summary in bytes:
// Measured: `0`
// Estimated: `1485`
// Minimum execution time: 4_339_000 picoseconds.
Weight::from_parts(4_688_000, 1485)
// Minimum execution time: 4_446_000 picoseconds.
Weight::from_parts(4_782_000, 1485)
.saturating_add(RocksDbWeight::get().reads(1_u64))
.saturating_add(RocksDbWeight::get().writes(2_u64))
}
@@ -196,8 +194,8 @@ impl WeightInfo for () {
// Proof Size summary in bytes:
// Measured: `0`
// Estimated: `1485`
// Minimum execution time: 82_624_498_000 picoseconds.
Weight::from_parts(83_553_373_000, 1485)
// Minimum execution time: 84_000_503_000 picoseconds.
Weight::from_parts(87_586_619_000, 1485)
.saturating_add(RocksDbWeight::get().reads(1_u64))
.saturating_add(RocksDbWeight::get().writes(2_u64))
}
@@ -208,10 +206,10 @@ impl WeightInfo for () {
// Proof Size summary in bytes:
// Measured: `0`
// Estimated: `0`
// Minimum execution time: 2_097_000 picoseconds.
Weight::from_parts(2_213_000, 0)
// Standard Error: 711
.saturating_add(Weight::from_parts(817_161, 0).saturating_mul(i.into()))
// Minimum execution time: 2_086_000 picoseconds.
Weight::from_parts(2_175_000, 0)
// Standard Error: 1_056
.saturating_add(Weight::from_parts(841_511, 0).saturating_mul(i.into()))
.saturating_add(RocksDbWeight::get().writes((1_u64).saturating_mul(i.into())))
}
/// Storage: Skipped Metadata (r:0 w:0)
@@ -221,10 +219,10 @@ impl WeightInfo for () {
// Proof Size summary in bytes:
// Measured: `0`
// Estimated: `0`
// Minimum execution time: 2_061_000 picoseconds.
Weight::from_parts(2_207_000, 0)
// Standard Error: 887
.saturating_add(Weight::from_parts(616_055, 0).saturating_mul(i.into()))
// Minimum execution time: 2_000_000 picoseconds.
Weight::from_parts(2_255_000, 0)
// Standard Error: 1_425
.saturating_add(Weight::from_parts(662_473, 0).saturating_mul(i.into()))
.saturating_add(RocksDbWeight::get().writes((1_u64).saturating_mul(i.into())))
}
/// Storage: Skipped Metadata (r:0 w:0)
@@ -234,10 +232,10 @@ impl WeightInfo for () {
// Proof Size summary in bytes:
// Measured: `115 + p * (69 ±0)`
// Estimated: `128 + p * (70 ±0)`
// Minimum execution time: 3_857_000 picoseconds.
Weight::from_parts(4_094_000, 128)
// Standard Error: 1_935
.saturating_add(Weight::from_parts(1_342_833, 0).saturating_mul(p.into()))
// Minimum execution time: 4_189_000 picoseconds.
Weight::from_parts(4_270_000, 128)
// Standard Error: 2_296
.saturating_add(Weight::from_parts(1_389_650, 0).saturating_mul(p.into()))
.saturating_add(RocksDbWeight::get().reads((1_u64).saturating_mul(p.into())))
.saturating_add(RocksDbWeight::get().writes((1_u64).saturating_mul(p.into())))
.saturating_add(Weight::from_parts(0, 70).saturating_mul(p.into()))