From 9638682a897ed7581832d96a3dc76ba5407b1537 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Duarte?= Date: Mon, 23 Dec 2024 13:59:57 +0000 Subject: [PATCH] benchmarks --- node/benchmark_template.hbs | 127 +++++++++++++++++++++++++ pallets/randomness/src/benchmarking.rs | 14 ++- pallets/randomness/weights.rs | 89 +++++++++++++++++ 3 files changed, 229 insertions(+), 1 deletion(-) create mode 100644 node/benchmark_template.hbs create mode 100644 pallets/randomness/weights.rs diff --git a/node/benchmark_template.hbs b/node/benchmark_template.hbs new file mode 100644 index 00000000..dcd2a6e5 --- /dev/null +++ b/node/benchmark_template.hbs @@ -0,0 +1,127 @@ +{{header}} +//! Autogenerated weights for `{{pallet}}` +//! +//! THIS FILE WAS AUTO-GENERATED USING THE SUBSTRATE BENCHMARK CLI VERSION {{version}} +//! DATE: {{date}}, STEPS: `{{cmd.steps}}`, REPEAT: `{{cmd.repeat}}`, LOW RANGE: `{{cmd.lowest_range_values}}`, HIGH RANGE: `{{cmd.highest_range_values}}` +//! WORST CASE MAP SIZE: `{{cmd.worst_case_map_values}}` +//! HOSTNAME: `{{hostname}}`, CPU: `{{cpuname}}` +//! WASM-EXECUTION: `{{cmd.wasm_execution}}`, CHAIN: `{{cmd.chain}}`, DB CACHE: {{cmd.db_cache}} + +// Executed Command: +{{#each args as |arg|}} +// {{arg}} +{{/each}} + +#![cfg_attr(rustfmt, rustfmt_skip)] +#![allow(unused_parens)] +#![allow(unused_imports)] +#![allow(missing_docs)] + +use frame_support::{traits::Get, weights::Weight}; +use core::marker::PhantomData; +use crate as {{pallet}}; + +trait WeightInfo { + {{#each benchmarks as |benchmark|}} + fn {{benchmark.name~}}( + {{~#each benchmark.components as |c| ~}} + {{~#if (not c.is_used)}}_{{/if}}{{c.name}}: u32, {{/each~}} + ) -> Weight; + {{/each}} +} + +/// Weight functions for `{{pallet}}`. +pub struct Weights(PhantomData); +{{#if (eq pallet "frame_system_extensions")}} +impl frame_system::ExtensionsWeightInfo for Weights { +{{else}} +impl {{pallet}}::WeightInfo for Weights { +{{/if}} + {{#each benchmarks as |benchmark|}} + {{#each benchmark.comments as |comment|}} + /// {{comment}} + {{/each}} + {{#each benchmark.component_ranges as |range|}} + /// The range of component `{{range.name}}` is `[{{range.min}}, {{range.max}}]`. + {{/each}} + fn {{benchmark.name~}} + ( + {{~#each benchmark.components as |c| ~}} + {{~#if (not c.is_used)}}_{{/if}}{{c.name}}: u32, {{/each~}} + ) -> Weight { + // Proof Size summary in bytes: + // Measured: `{{benchmark.base_recorded_proof_size}}{{#each benchmark.component_recorded_proof_size as |cp|}} + {{cp.name}} * ({{cp.slope}} ±{{underscore cp.error}}){{/each}}` + // Estimated: `{{benchmark.base_calculated_proof_size}}{{#each benchmark.component_calculated_proof_size as |cp|}} + {{cp.name}} * ({{cp.slope}} ±{{underscore cp.error}}){{/each}}` + // Minimum execution time: {{underscore benchmark.min_execution_time}}_000 picoseconds. + Weight::from_parts({{underscore benchmark.base_weight}}, 0) + .saturating_add(Weight::from_parts(0, {{benchmark.base_calculated_proof_size}})) + {{#each benchmark.component_weight as |cw|}} + // Standard Error: {{underscore cw.error}} + .saturating_add(Weight::from_parts({{underscore cw.slope}}, 0).saturating_mul({{cw.name}}.into())) + {{/each}} + {{#if (ne benchmark.base_reads "0")}} + .saturating_add(T::DbWeight::get().reads({{benchmark.base_reads}})) + {{/if}} + {{#each benchmark.component_reads as |cr|}} + .saturating_add(T::DbWeight::get().reads(({{cr.slope}}_u64).saturating_mul({{cr.name}}.into()))) + {{/each}} + {{#if (ne benchmark.base_writes "0")}} + .saturating_add(T::DbWeight::get().writes({{benchmark.base_writes}})) + {{/if}} + {{#each benchmark.component_writes as |cw|}} + .saturating_add(T::DbWeight::get().writes(({{cw.slope}}_u64).saturating_mul({{cw.name}}.into()))) + {{/each}} + {{#each benchmark.component_calculated_proof_size as |cp|}} + .saturating_add(Weight::from_parts(0, {{cp.slope}}).saturating_mul({{cp.name}}.into())) + {{/each}} + } + {{/each}} +} + +{{#if (eq pallet "frame_system_extensions")}} +impl frame_system::ExtensionsWeightInfo for () { +{{else}} +impl {{pallet}}::WeightInfo for () { +{{/if}} + {{#each benchmarks as |benchmark|}} + {{#each benchmark.comments as |comment|}} + /// {{comment}} + {{/each}} + {{#each benchmark.component_ranges as |range|}} + /// The range of component `{{range.name}}` is `[{{range.min}}, {{range.max}}]`. + {{/each}} + fn {{benchmark.name~}} + ( + {{~#each benchmark.components as |c| ~}} + {{~#if (not c.is_used)}}_{{/if}}{{c.name}}: u32, {{/each~}} + ) -> Weight { + use frame_support::constants::RocksDbWeight; + + // Proof Size summary in bytes: + // Measured: `{{benchmark.base_recorded_proof_size}}{{#each benchmark.component_recorded_proof_size as |cp|}} + {{cp.name}} * ({{cp.slope}} ±{{underscore cp.error}}){{/each}}` + // Estimated: `{{benchmark.base_calculated_proof_size}}{{#each benchmark.component_calculated_proof_size as |cp|}} + {{cp.name}} * ({{cp.slope}} ±{{underscore cp.error}}){{/each}}` + // Minimum execution time: {{underscore benchmark.min_execution_time}}_000 picoseconds. + Weight::from_parts({{underscore benchmark.base_weight}}, 0) + .saturating_add(Weight::from_parts(0, {{benchmark.base_calculated_proof_size}})) + {{#each benchmark.component_weight as |cw|}} + // Standard Error: {{underscore cw.error}} + .saturating_add(Weight::from_parts({{underscore cw.slope}}, 0).saturating_mul({{cw.name}}.into())) + {{/each}} + {{#if (ne benchmark.base_reads "0")}} + .saturating_add(RocksDbWeight::get().reads({{benchmark.base_reads}})) + {{/if}} + {{#each benchmark.component_reads as |cr|}} + .saturating_add(RocksDbWeight::get().reads(({{cr.slope}}_u64).saturating_mul({{cr.name}}.into()))) + {{/each}} + {{#if (ne benchmark.base_writes "0")}} + .saturating_add(RocksDbWeight::get().writes({{benchmark.base_writes}})) + {{/if}} + {{#each benchmark.component_writes as |cw|}} + .saturating_add(RocksDbWeight::get().writes(({{cw.slope}}_u64).saturating_mul({{cw.name}}.into()))) + {{/each}} + {{#each benchmark.component_calculated_proof_size as |cp|}} + .saturating_add(Weight::from_parts(0, {{cp.slope}}).saturating_mul({{cp.name}}.into())) + {{/each}} + } + {{/each}} +} diff --git a/pallets/randomness/src/benchmarking.rs b/pallets/randomness/src/benchmarking.rs index 13edc06c..6535e7c3 100644 --- a/pallets/randomness/src/benchmarking.rs +++ b/pallets/randomness/src/benchmarking.rs @@ -17,10 +17,22 @@ mod benchmarks { /// Instead of just adding the randomness value, it requires removing the oldest value too. #[benchmark] fn set_author_vrf() { + use frame_system::pallet_prelude::BlockNumberFor; + + use crate::pallet::AuthorVrfHistory; + + // Add 256 blocks so we trigger the remove into insert logic + for block_number in 0..=256u32 { + AuthorVrfHistory::::insert::, T::Hash>( + block_number.into(), + Default::default(), + ); + } + #[extrinsic_call] _(RawOrigin::None); - let author_vrf = ::AuthorVrfGetter::get_author_vrf(); + let author_vrf = T::AuthorVrfGetter::get_author_vrf(); assert!(author_vrf.is_some()); } diff --git a/pallets/randomness/weights.rs b/pallets/randomness/weights.rs new file mode 100644 index 00000000..db40dfb5 --- /dev/null +++ b/pallets/randomness/weights.rs @@ -0,0 +1,89 @@ + +//! Autogenerated weights for `pallet_randomness` +//! +//! THIS FILE WAS AUTO-GENERATED USING THE SUBSTRATE BENCHMARK CLI VERSION 32.0.0 +//! DATE: 2024-12-23, STEPS: `50`, REPEAT: `20`, LOW RANGE: `[]`, HIGH RANGE: `[]` +//! WORST CASE MAP SIZE: `1000000` +//! HOSTNAME: `parthenon`, CPU: `12th Gen Intel(R) Core(TM) i7-12700H` +//! WASM-EXECUTION: `Compiled`, CHAIN: `None`, DB CACHE: 1024 + +// Executed Command: +// target/release/polka-storage-node +// benchmark +// pallet +// --wasm-execution=compiled +// --pallet +// pallet_randomness +// --extrinsic +// * +// --steps +// 50 +// --repeat +// 20 +// --output +// pallets/randomness/weights.rs +// --template +// node/benchmark_template.hbs + +#![cfg_attr(rustfmt, rustfmt_skip)] +#![allow(unused_parens)] +#![allow(unused_imports)] +#![allow(missing_docs)] + +use frame_support::{traits::Get, weights::Weight}; +use core::marker::PhantomData; +use crate as pallet_randomness; + +trait WeightInfo { + fn set_author_vrf() -> Weight; +} + +/// Weight functions for `pallet_randomness`. +pub struct Weights(PhantomData); +impl pallet_randomness::WeightInfo for Weights { + /// Storage: `ParachainSystem::ValidationData` (r:1 w:0) + /// Proof: `ParachainSystem::ValidationData` (`max_values`: Some(1), `max_size`: None, mode: `Measured`) + /// Storage: `ParachainSystem::RelayStateProof` (r:1 w:0) + /// Proof: `ParachainSystem::RelayStateProof` (`max_values`: Some(1), `max_size`: None, mode: `Measured`) + /// Storage: `Randomness::CounterForAuthorVrfHistory` (r:1 w:0) + /// Proof: `Randomness::CounterForAuthorVrfHistory` (`max_values`: Some(1), `max_size`: Some(4), added: 499, mode: `MaxEncodedLen`) + /// Storage: `Randomness::AuthorVrfHistory` (r:1 w:1) + /// Proof: `Randomness::AuthorVrfHistory` (`max_values`: None, `max_size`: Some(48), added: 2523, mode: `MaxEncodedLen`) + /// Storage: `Randomness::AuthorVrf` (r:0 w:1) + /// Proof: `Randomness::AuthorVrf` (`max_values`: Some(1), `max_size`: Some(32), added: 527, mode: `MaxEncodedLen`) + fn set_author_vrf() -> Weight { + // Proof Size summary in bytes: + // Measured: `1052` + // Estimated: `3513` + // Minimum execution time: 16_315_000 picoseconds. + Weight::from_parts(17_210_000, 0) + .saturating_add(Weight::from_parts(0, 3513)) + .saturating_add(T::DbWeight::get().reads(4)) + .saturating_add(T::DbWeight::get().writes(2)) + } +} + +impl pallet_randomness::WeightInfo for () { + /// Storage: `ParachainSystem::ValidationData` (r:1 w:0) + /// Proof: `ParachainSystem::ValidationData` (`max_values`: Some(1), `max_size`: None, mode: `Measured`) + /// Storage: `ParachainSystem::RelayStateProof` (r:1 w:0) + /// Proof: `ParachainSystem::RelayStateProof` (`max_values`: Some(1), `max_size`: None, mode: `Measured`) + /// Storage: `Randomness::CounterForAuthorVrfHistory` (r:1 w:0) + /// Proof: `Randomness::CounterForAuthorVrfHistory` (`max_values`: Some(1), `max_size`: Some(4), added: 499, mode: `MaxEncodedLen`) + /// Storage: `Randomness::AuthorVrfHistory` (r:1 w:1) + /// Proof: `Randomness::AuthorVrfHistory` (`max_values`: None, `max_size`: Some(48), added: 2523, mode: `MaxEncodedLen`) + /// Storage: `Randomness::AuthorVrf` (r:0 w:1) + /// Proof: `Randomness::AuthorVrf` (`max_values`: Some(1), `max_size`: Some(32), added: 527, mode: `MaxEncodedLen`) + fn set_author_vrf() -> Weight { + use frame_support::constants::RocksDbWeight; + + // Proof Size summary in bytes: + // Measured: `1052` + // Estimated: `3513` + // Minimum execution time: 16_315_000 picoseconds. + Weight::from_parts(17_210_000, 0) + .saturating_add(Weight::from_parts(0, 3513)) + .saturating_add(RocksDbWeight::get().reads(4)) + .saturating_add(RocksDbWeight::get().writes(2)) + } +}