Add Proof Size to Weight Output (#11637)

* initial impl

* add template test

* linear fit proof size

* always record proof when tracking storage

* calculate worst case pov

* remove duplicate worst case

* cargo run --quiet --profile=production  --features=runtime-benchmarks --manifest-path=bin/node/cli/Cargo.toml -- benchmark pallet --chain=dev --steps=50 --repeat=20 --pallet=pallet_assets --extrinsic=* --execution=wasm --wasm-execution=compiled --heap-pages=4096 --output=./frame/assets/src/weights.rs --template=./.maintain/frame-weight-template.hbs

* more comment output

* add cli for worst case map size

* update name

* clap does not support underscores

* rename

* expose worst case map values

* improve some comments

* cargo run --quiet --profile=production  --features=runtime-benchmarks --manifest-path=bin/node/cli/Cargo.toml -- benchmark pallet --chain=dev --steps=50 --repeat=20 --pallet=pallet_assets --extrinsic=* --execution=wasm --wasm-execution=compiled --heap-pages=4096 --output=./frame/assets/src/weights.rs --template=./.maintain/frame-weight-template.hbs

* update template

* cargo run --quiet --profile=production  --features=runtime-benchmarks --manifest-path=bin/node/cli/Cargo.toml -- benchmark pallet --chain=dev --steps=50 --repeat=20 --pallet=pallet_assets --extrinsic=* --execution=wasm --wasm-execution=compiled --heap-pages=4096 --output=./frame/assets/src/weights.rs --template=./.maintain/frame-weight-template.hbs

* fix fmt

* more fmt

* more fmt

* Dont panic when there is no proof

Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io>

* Fix test features

Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io>

* Whitelist :extrinsic_index

Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io>

* Use whitelist when recording proof

Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io>

* Add logs

Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io>

* Add PoV testing pallet

Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io>

* Deploy PoV testing pallet

Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io>

* Storage benches reside in the PoV pallet

Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io>

* Linear regress PoV per component

Splits the PoV calculation into "measured" and "estimated".
The measured part is reported by the Proof recorder and linear
regressed over all components at once.
The estimated part is calculated as worst-case by using the max
PoV size per storage access and calculating one linear regress per
component. This gives each component a (possibly) independent PoV.
For now the measured size will always be lower than the PoV on
Polkadot since it is measured on an empty snapshot. The measured
part is therefor only used as diagnostic for debugging.

Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io>

* Put PoV into the weight templates

Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io>

* fmt

Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io>

* Extra alanysis choise for PoV

Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io>

* Add+Fix tests

Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io>

* Make benches faster

Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io>

* Cleanup

Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io>

* Use same template comments

Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io>

* ".git/.scripts/bench-bot.sh" pallet dev pallet_balances

* ".git/.scripts/bench-bot.sh" pallet dev pallet_democracy

* Update referenda mock BlockWeights

Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io>

* Take measured value size into account

Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io>

* clippy

Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io>

* ".git/.scripts/bench-bot.sh" pallet dev pallet_scheduler

* WIP

Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io>

* proof_size: None

Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io>

* WIP

Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io>

* WIP

Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io>

* WIP

Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io>

* ugly, but works

Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io>

* WIP

Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io>

* WIP

Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io>

* WIP

Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io>

* wup

Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io>

* WIP

Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io>

* WIP

Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io>

* WIP

Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io>

* WIP

Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io>

* Add pov_mode attribute to the benchmarks! macro

Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io>

* Use pov_mode attribute in PoV benchmarking

Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io>

* Update tests

Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io>

* Scheduler, Whitelist: Add pov_mode attr

Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io>

* Update PoV weights

* Add CLI arg: default-pov-mode

Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io>

* Fix tests

Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io>

* fmt

Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io>

* fix

Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io>

* Revert "Update PoV weights"

This reverts commit 2f3ac2387396470b118122a6ff8fa4ee12216f4b.

* Revert "WIP"

This reverts commit c34b538cd2bc45da4544e887180184e30957904a.

* Revert first approach

This reverts commit range 8ddaa2fffe5930f225a30bee314d0b7c94c344dd^..4c84f8748e5395852a9e0e25b0404953fee1a59e

Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io>

* Clippy

Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io>

* Add extra benchmarks

Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io>

* ".git/.scripts/commands/bench/bench.sh" pallet dev pallet_alliance

* ".git/.scripts/commands/bench/bench.sh" pallet dev pallet_whitelist

* ".git/.scripts/commands/bench/bench.sh" pallet dev pallet_scheduler

* fmt

Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io>

* Clippy

Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io>

* Clippy 🤦

Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io>

* Add reference benchmarks

Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io>

* Fix doc comments

Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io>

* Undo logging

Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io>

* Add 'Ignored' pov_mode

Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io>

* Allow multiple attributes per benchmark

Turns out that the current benchmarking syntax does not support
multiple attributes per bench 🤦. Changing it to support that
since otherwise the `pov_mode` would conflict with the others.

Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io>

* Validate pov_mode syntax

Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io>

* Ignore PoV for all contract benchmarks

Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io>

* Test

Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io>

* test

Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io>

* Bump macro recursion limit

Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io>

* fmt

Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io>

* Update contract weights

They dont have a PoV component anymore.

Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io>

* fix test ffs

Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io>

* pov_mode is unsupported in V2 syntax

Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io>

* Fix pallet ui tests

Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io>

* update pallet ui

Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io>

* Fix pallet ui tests

Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io>

* Update weights

Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io>

Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io>
Co-authored-by: Parity Bot <admin@parity.io>
Co-authored-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io>
Co-authored-by: command-bot <>
Co-authored-by: Your Name <you@example.com>
This commit is contained in:
Shawn Tabrizi
2023-01-26 19:35:39 -03:00
committed by GitHub
parent 41f819eb48
commit 1b27ae9549
74 changed files with 18668 additions and 9111 deletions
+11 -52
View File
@@ -16,29 +16,25 @@
// limitations under the License.
//! A set of benchmarks which can establish a global baseline for all other
//! benchmarking.
//! benchmarking. These benchmarks do not require a pallet to be deployed.
#![cfg(feature = "runtime-benchmarks")]
use super::*;
use crate::benchmarks;
use codec::Encode;
use frame_system::Pallet as System;
use sp_application_crypto::KeyTypeId;
use sp_runtime::{
traits::{AppVerify, Hash},
RuntimeAppPublic,
};
use sp_std::prelude::*;
pub const TEST_KEY_TYPE_ID: KeyTypeId = KeyTypeId(*b"test");
mod crypto {
use sp_application_crypto::{app_crypto, sr25519, KeyTypeId};
mod app_sr25519 {
use super::TEST_KEY_TYPE_ID;
use sp_application_crypto::{app_crypto, sr25519};
pub const TEST_KEY_TYPE_ID: KeyTypeId = KeyTypeId(*b"test");
app_crypto!(sr25519, TEST_KEY_TYPE_ID);
}
type SignerId = app_sr25519::Public;
pub type SignerId = crypto::Public;
pub struct Pallet<T: Config>(System<T>);
pub trait Config: frame_system::Config {}
@@ -81,7 +77,6 @@ benchmarks! {
}
hashing {
let i in 0 .. 100;
let mut hash = T::Hash::default();
}: {
(0..=100_000u32).for_each(|j| hash = T::Hashing::hash(&j.to_be_bytes()));
@@ -106,53 +101,17 @@ benchmarks! {
});
}
#[skip_meta]
storage_read {
let i in 0 .. 1_000;
let mut people = Vec::new();
(0..i).for_each(|j| {
let hash = T::Hashing::hash(&j.to_be_bytes()).encode();
frame_support::storage::unhashed::put(&hash, &hash);
people.push(hash);
});
}: {
people.iter().for_each(|hash| {
// This does a storage read
let value = frame_support::storage::unhashed::get(hash);
assert_eq!(value, Some(hash.to_vec()));
});
}
#[skip_meta]
storage_write {
let i in 0 .. 1_000;
let mut hashes = Vec::new();
(0..i).for_each(|j| {
let hash = T::Hashing::hash(&j.to_be_bytes());
hashes.push(hash.encode());
});
}: {
hashes.iter().for_each(|hash| {
// This does a storage write
frame_support::storage::unhashed::put(hash, hash);
});
} verify {
hashes.iter().for_each(|hash| {
let value = frame_support::storage::unhashed::get(hash);
assert_eq!(value, Some(hash.to_vec()));
});
}
impl_benchmark_test_suite!(
Pallet,
crate::baseline::mock::new_test_ext(),
crate::baseline::mock::Test,
mock::new_test_ext(),
mock::Test,
);
}
#[cfg(test)]
pub mod mock {
use sp_runtime::{testing::H256, traits::IdentityLookup};
use super::*;
use sp_runtime::testing::H256;
type AccountId = u64;
type AccountIndex = u32;
@@ -183,7 +142,7 @@ pub mod mock {
type Hash = H256;
type Hashing = ::sp_runtime::traits::BlakeTwo256;
type AccountId = AccountId;
type Lookup = IdentityLookup<Self::AccountId>;
type Lookup = sp_runtime::traits::IdentityLookup<Self::AccountId>;
type Header = sp_runtime::testing::Header;
type RuntimeEvent = RuntimeEvent;
type BlockHashCount = ();
+127 -5
View File
@@ -47,7 +47,7 @@ pub use sp_runtime::traits::Zero;
pub use sp_runtime::StateVersion;
#[doc(hidden)]
pub use sp_std::{self, boxed::Box, prelude::Vec, str, vec};
pub use sp_storage::TrackedStorageKey;
pub use sp_storage::{well_known_keys, TrackedStorageKey};
pub use utils::*;
/// Whitelist the given account.
@@ -211,6 +211,7 @@ macro_rules! benchmarks {
( )
( )
( )
( )
$( $rest )*
);
}
@@ -231,6 +232,7 @@ macro_rules! benchmarks_instance {
( )
( )
( )
( )
$( $rest )*
);
}
@@ -251,6 +253,7 @@ macro_rules! benchmarks_instance_pallet {
( )
( )
( )
( )
$( $rest )*
);
}
@@ -268,6 +271,7 @@ macro_rules! benchmarks_iter {
( $( $names:tt )* )
( $( $names_extra:tt )* )
( $( $names_skip_meta:tt )* )
( $( $pov_name:ident: $( $storage:path = $pov_mode:ident )*; )* )
impl_benchmark_test_suite!(
$bench_module:ident,
$new_test_ext:expr,
@@ -282,6 +286,7 @@ macro_rules! benchmarks_iter {
( $( $names )* )
( $( $names_extra )* )
( $( $names_skip_meta )* )
( $( $pov_name: $( $storage = $pov_mode )*; )* )
$( $rest )*
}
};
@@ -293,6 +298,7 @@ macro_rules! benchmarks_iter {
( $( $names:tt )* )
( $( $names_extra:tt )* )
( $( $names_skip_meta:tt )* )
( $( $pov_name:ident: $( $storage:path = $pov_mode:ident )*; )* )
impl_benchmark_test_suite!(
$bench_module:ident,
$new_test_ext:expr,
@@ -307,6 +313,7 @@ macro_rules! benchmarks_iter {
( $( $names )* )
( $( $names_extra )* )
( $( $names_skip_meta )* )
( $( $pov_name: $( $storage = $pov_mode )*; )* )
$( $rest )*
}
};
@@ -318,6 +325,7 @@ macro_rules! benchmarks_iter {
( $( $names:tt )* )
( $( $names_extra:tt )* )
( $( $names_skip_meta:tt )* )
( $( $pov_name:ident: $( $storage:path = $pov_mode:ident )*; )* )
where_clause { where $( $where_bound:tt )* }
$( $rest:tt )*
) => {
@@ -328,6 +336,7 @@ macro_rules! benchmarks_iter {
( $( $names )* )
( $( $names_extra )* )
( $( $names_skip_meta )* )
( $( $pov_name: $( $storage = $pov_mode )*; )* )
$( $rest )*
}
};
@@ -339,7 +348,9 @@ macro_rules! benchmarks_iter {
( $( $names:tt )* )
( $( $names_extra:tt )* )
( $( $names_skip_meta:tt )* )
( $( $pov_name:ident: $( $storage:path = $pov_mode:ident )*; )* )
#[skip_meta]
$( #[ $($attributes:tt)+ ] )*
$name:ident
$( $rest:tt )*
) => {
@@ -350,6 +361,8 @@ macro_rules! benchmarks_iter {
( $( $names )* )
( $( $names_extra )* )
( $( $names_skip_meta )* $name )
( $( $pov_name: $( $storage = $pov_mode )*; )* )
$( #[ $( $attributes )+ ] )*
$name
$( $rest )*
}
@@ -362,7 +375,9 @@ macro_rules! benchmarks_iter {
( $( $names:tt )* )
( $( $names_extra:tt )* )
( $( $names_skip_meta:tt )* )
( $( $pov_name:ident: $( $storage:path = $pov_mode:ident )*; )* )
#[extra]
$( #[ $($attributes:tt)+ ] )*
$name:ident
$( $rest:tt )*
) => {
@@ -373,6 +388,35 @@ macro_rules! benchmarks_iter {
( $( $names )* )
( $( $names_extra )* $name )
( $( $names_skip_meta )* )
( $( $pov_name: $( $storage = $pov_mode )*; )* )
$( #[ $( $attributes )+ ] )*
$name
$( $rest )*
}
};
// detect and extract `#[pov_mode = Mode { Pallet::Storage: Mode ... }]` tag:
(
{ $($bench_module:ident, $new_test_ext:expr, $test:path $(, $( $args:tt )* )?)? }
{ $( $instance:ident: $instance_bound:tt )? }
{ $( $where_clause:tt )* }
( $( $names:tt )* )
( $( $names_extra:tt )* )
( $( $names_skip_meta:tt )* )
( $( $old_pov_name:ident: $( $old_storage:path = $old_pov_mode:ident )*; )* )
#[pov_mode = $mode:ident $( { $( $storage:path: $pov_mode:ident )* } )?]
$( #[ $($attributes:tt)+ ] )*
$name:ident
$( $rest:tt )*
) => {
$crate::benchmarks_iter! {
{ $($bench_module, $new_test_ext, $test $(, $( $args )* )?)? }
{ $( $instance: $instance_bound )? }
{ $( $where_clause )* }
( $( $names )* )
( $( $names_extra )* )
( $( $names_skip_meta )* )
( $name: ALL = $mode $($( $storage = $pov_mode )*)?; $( $old_pov_name: $( $old_storage = $old_pov_mode )*; )* )
$( #[ $( $attributes )+ ] )*
$name
$( $rest )*
}
@@ -385,6 +429,7 @@ macro_rules! benchmarks_iter {
( $( $names:tt )* ) // This contains $( $( { $instance } )? $name:ident )*
( $( $names_extra:tt )* )
( $( $names_skip_meta:tt )* )
( $( $pov_name:ident: $( $storage:path = $pov_mode:ident )*; )* )
$name:ident { $( $code:tt )* }: _ $(< $origin_type:ty>)? ( $origin:expr $( , $arg:expr )* )
verify $postcode:block
$( $rest:tt )*
@@ -396,6 +441,7 @@ macro_rules! benchmarks_iter {
( $( $names )* )
( $( $names_extra )* )
( $( $names_skip_meta )* )
( $( $pov_name: $( $storage = $pov_mode )*; )* )
$name { $( $code )* }: $name $(< $origin_type >)? ( $origin $( , $arg )* )
verify $postcode
$( $rest )*
@@ -409,6 +455,7 @@ macro_rules! benchmarks_iter {
( $( $names:tt )* )
( $( $names_extra:tt )* )
( $( $names_skip_meta:tt )* )
( $( $pov_name:ident: $( $storage:path = $pov_mode:ident )*; )* )
$name:ident { $( $code:tt )* }: $dispatch:ident $(<$origin_type:ty>)? ( $origin:expr $( , $arg:expr )* )
verify $postcode:block
$( $rest:tt )*
@@ -421,6 +468,7 @@ macro_rules! benchmarks_iter {
( $( $names )* )
( $( $names_extra )* )
( $( $names_skip_meta )* )
( $( $pov_name: $( $storage = $pov_mode )*; )* )
$name {
$( $code )*
let __call = Call::<
@@ -455,6 +503,7 @@ macro_rules! benchmarks_iter {
( $( $names:tt )* )
( $( $names_extra:tt )* )
( $( $names_skip_meta:tt )* )
( $( $pov_name:ident: $( $storage:path = $pov_mode:ident )*; )* )
$name:ident { $( $code:tt )* }: $eval:block
verify $postcode:block
$( $rest:tt )*
@@ -483,6 +532,7 @@ macro_rules! benchmarks_iter {
( $( $names )* { $( $instance )? } $name )
( $( $names_extra )* )
( $( $names_skip_meta )* )
( $( $pov_name: $( $storage = $pov_mode )*; )* )
$( $rest )*
);
};
@@ -494,6 +544,7 @@ macro_rules! benchmarks_iter {
( $( $names:tt )* )
( $( $names_extra:tt )* )
( $( $names_skip_meta:tt )* )
( $( $pov_name:ident: $( $storage:path = $pov_mode:ident )*; )* )
) => {
$crate::selected_benchmark!(
{ $( $where_clause)* }
@@ -506,6 +557,7 @@ macro_rules! benchmarks_iter {
( $( $names )* )
( $( $names_extra ),* )
( $( $names_skip_meta ),* )
( $( $pov_name: $( $storage = $pov_mode )*; )* )
);
$crate::impl_test_function!(
( $( $names )* )
@@ -525,6 +577,7 @@ macro_rules! benchmarks_iter {
( $( $names:tt )* )
( $( $names_extra:tt )* )
( $( $names_skip_meta:tt )* )
( $( $pov_name:ident: $( $storage:path = $pov_mode:ident )*; )* )
) => {
$crate::selected_benchmark!(
{ $( $where_clause)* }
@@ -537,6 +590,7 @@ macro_rules! benchmarks_iter {
( $( $names )* )
( $( $names_extra ),* )
( $( $names_skip_meta ),* )
( $( $pov_name: $( $storage = $pov_mode )*; )* )
);
};
// add verify block to _() format
@@ -547,6 +601,7 @@ macro_rules! benchmarks_iter {
( $( $names:tt )* )
( $( $names_extra:tt )* )
( $( $names_skip_meta:tt )* )
( $( $pov_name:ident: $( $storage:path = $pov_mode:ident )*; )* )
$name:ident { $( $code:tt )* }: _ $(<$origin_type:ty>)? ( $origin:expr $( , $arg:expr )* )
$( $rest:tt )*
) => {
@@ -557,6 +612,7 @@ macro_rules! benchmarks_iter {
( $( $names )* )
( $( $names_extra )* )
( $( $names_skip_meta )* )
( $( $pov_name: $( $storage = $pov_mode )*; )* )
$name { $( $code )* }: _ $(<$origin_type>)? ( $origin $( , $arg )* )
verify { }
$( $rest )*
@@ -570,6 +626,7 @@ macro_rules! benchmarks_iter {
( $( $names:tt )* )
( $( $names_extra:tt )* )
( $( $names_skip_meta:tt )* )
( $( $pov_name:ident: $( $storage:path = $pov_mode:ident )*; )* )
$name:ident { $( $code:tt )* }: $dispatch:ident $(<$origin_type:ty>)? ( $origin:expr $( , $arg:expr )* )
$( $rest:tt )*
) => {
@@ -580,6 +637,7 @@ macro_rules! benchmarks_iter {
( $( $names )* )
( $( $names_extra )* )
( $( $names_skip_meta )* )
( $( $pov_name: $( $storage = $pov_mode )*; )* )
$name { $( $code )* }: $dispatch $(<$origin_type>)? ( $origin $( , $arg )* )
verify { }
$( $rest )*
@@ -593,6 +651,7 @@ macro_rules! benchmarks_iter {
( $( $names:tt )* )
( $( $names_extra:tt )* )
( $( $names_skip_meta:tt )* )
( $( $pov_name:ident: $( $storage:path = $pov_mode:ident )*; )* )
$name:ident { $( $code:tt )* }: $(<$origin_type:ty>)? $eval:block
$( $rest:tt )*
) => {
@@ -603,6 +662,7 @@ macro_rules! benchmarks_iter {
( $( $names )* )
( $( $names_extra )* )
( $( $names_skip_meta )* )
( $( $pov_name: $( $storage = $pov_mode )*; )* )
$name { $( $code )* }: $(<$origin_type>)? $eval
verify { }
$( $rest )*
@@ -981,6 +1041,7 @@ macro_rules! impl_benchmark {
( $( { $( $name_inst:ident )? } $name:ident )* )
( $( $name_extra:ident ),* )
( $( $name_skip_meta:ident ),* )
( $( $pov_name:ident: $( $storage:path = $pov_mode:ident )*; )* )
) => {
// We only need to implement benchmarks for the runtime-benchmarks feature or testing.
#[cfg(any(feature = "runtime-benchmarks", test))]
@@ -989,23 +1050,37 @@ macro_rules! impl_benchmark {
where T: frame_system::Config, $( $where_clause )*
{
fn benchmarks(extra: bool) -> $crate::Vec<$crate::BenchmarkMetadata> {
$($crate::validate_pov_mode!(
$pov_name: $( $storage = $pov_mode )*;
);)*
let mut all_names = $crate::vec![ $( stringify!($name).as_ref() ),* ];
if !extra {
let extra = [ $( stringify!($name_extra).as_ref() ),* ];
all_names.retain(|x| !extra.contains(x));
}
let pov_modes: $crate::Vec<($crate::Vec<u8>, $crate::Vec<($crate::Vec<u8>, $crate::Vec<u8>)>)> = $crate::vec![
$(
(stringify!($pov_name).as_bytes().to_vec(),
$crate::vec![
$( ( stringify!($storage).as_bytes().to_vec(),
stringify!($pov_mode).as_bytes().to_vec() ), )*
]),
)*
];
all_names.into_iter().map(|benchmark| {
let selected_benchmark = match benchmark {
$( stringify!($name) => SelectedBenchmark::$name, )*
_ => panic!("all benchmarks should be selectable"),
};
let name = benchmark.as_bytes().to_vec();
let components = <
SelectedBenchmark as $crate::BenchmarkingSetup<T $(, $instance)?>
>::components(&selected_benchmark);
$crate::BenchmarkMetadata {
name: benchmark.as_bytes().to_vec(),
name: name.clone(),
components,
pov_modes: pov_modes.iter().find(|p| p.0 == name).map(|p| p.1.clone()).unwrap_or_default(),
}
}).collect::<$crate::Vec<_>>()
}
@@ -1037,8 +1112,13 @@ macro_rules! impl_benchmark {
$crate::frame_support::storage::transactional::TRANSACTION_LEVEL_KEY.into()
);
whitelist.push(transactional_layer_key);
// Whitelist the `:extrinsic_index`.
let extrinsic_index = $crate::TrackedStorageKey::new(
$crate::well_known_keys::EXTRINSIC_INDEX.into()
);
whitelist.push(extrinsic_index);
$crate::benchmarking::set_whitelist(whitelist);
$crate::benchmarking::set_whitelist(whitelist.clone());
let mut results: $crate::Vec<$crate::BenchmarkResult> = $crate::Vec::new();
@@ -1062,15 +1142,22 @@ macro_rules! impl_benchmark {
// This will enable worst case scenario for reading from the database.
$crate::benchmarking::commit_db();
// Access all whitelisted keys to get them into the proof recorder since the
// recorder does now have a whitelist.
for key in &whitelist {
$crate::frame_support::storage::unhashed::get_raw(&key.key);
}
// Reset the read/write counter so we don't count operations in the setup process.
$crate::benchmarking::reset_read_write_count();
// Time the extrinsic logic.
$crate::log::trace!(
target: "benchmark",
"Start Benchmark: {} ({:?})",
"Start Benchmark: {} ({:?}) verify {}",
extrinsic,
c
c,
verify
);
let start_pov = $crate::benchmarking::proof_size();
@@ -1099,6 +1186,10 @@ macro_rules! impl_benchmark {
target: "benchmark",
"Read/Write Count {:?}", read_write_count
);
$crate::log::trace!(
target: "benchmark",
"Proof sizes: before {:?} after {:?} diff {}", &start_pov, &end_pov, &diff_pov
);
// Time the storage root recalculation.
let start_storage_root = $crate::benchmarking::current_time();
@@ -1421,6 +1512,37 @@ macro_rules! impl_benchmark_test_suite {
}
}
/// Validates the passed `pov_mode`s.
///
/// Checks that:
/// - a top-level `ignored` is exclusive
/// - all modes are valid
#[macro_export]
macro_rules! validate_pov_mode {
() => {};
( $_bench:ident: ; ) => { };
( $_bench:ident: $_car:path = Ignored ; ) => { };
( $bench:ident: $_car:path = Ignored $( $storage:path = $_pov_mode:ident )+; ) => {
compile_error!(
concat!(concat!("`pov_mode = Ignored` is exclusive. Please remove the attribute from keys: ", $( stringify!($storage) )+), " on benchmark '", stringify!($bench), "'"));
};
( $bench:ident: $car:path = Measured $( $storage:path = $pov_mode:ident )*; ) => {
$crate::validate_pov_mode!(
$bench: $( $storage = $pov_mode )*;
);
};
( $bench:ident: $car:path = MaxEncodedLen $( $storage:path = $pov_mode:ident )*; ) => {
$crate::validate_pov_mode!(
$bench: $( $storage = $pov_mode )*;
);
};
( $bench:ident: $key:path = $unknown:ident $( $_storage:path = $_pov_mode:ident )*; ) => {
compile_error!(
concat!("Unknown pov_mode '", stringify!($unknown) ,"' for benchmark '", stringify!($bench), "' on key '", stringify!($key), "'. Must be one of: Ignored, Measured, MaxEncodedLen")
);
};
}
// Takes all arguments from `impl_benchmark_test_suite` and three additional arguments.
//
// Can be configured to generate one #[test] fn per bench case or
@@ -227,6 +227,7 @@ pub struct BenchmarkList {
pub struct BenchmarkMetadata {
pub name: Vec<u8>,
pub components: Vec<(BenchmarkParameter, u32, u32)>,
pub pov_modes: Vec<(Vec<u8>, Vec<u8>)>,
}
sp_api::decl_runtime_apis! {
+70 -73
View File
@@ -1,6 +1,6 @@
// This file is part of Substrate.
// Copyright (C) 2022 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");
@@ -18,7 +18,8 @@
//! Autogenerated weights for frame_benchmarking
//!
//! THIS FILE WAS AUTO-GENERATED USING THE SUBSTRATE BENCHMARK CLI VERSION 4.0.0-dev
//! DATE: 2022-11-07, STEPS: `50`, REPEAT: 20, LOW RANGE: `[]`, HIGH RANGE: `[]`
//! DATE: 2023-01-24, STEPS: `50`, REPEAT: `20`, LOW RANGE: `[]`, HIGH RANGE: `[]`
//! WORST CASE MAP SIZE: `1000000`
//! HOSTNAME: `bm2`, CPU: `Intel(R) Core(TM) i7-7700K CPU @ 4.20GHz`
//! EXECUTION: Some(Wasm), WASM-EXECUTION: Compiled, CHAIN: Some("dev"), DB CACHE: 1024
@@ -51,10 +52,8 @@ pub trait WeightInfo {
fn subtraction(i: u32, ) -> Weight;
fn multiplication(i: u32, ) -> Weight;
fn division(i: u32, ) -> Weight;
fn hashing(i: u32, ) -> Weight;
fn hashing() -> Weight;
fn sr25519_verification(i: u32, ) -> Weight;
fn storage_read(i: u32, ) -> Weight;
fn storage_write(i: u32, ) -> Weight;
}
/// Weights for frame_benchmarking using the Substrate node and recommended hardware.
@@ -62,53 +61,52 @@ pub struct SubstrateWeight<T>(PhantomData<T>);
impl<T: frame_system::Config> WeightInfo for SubstrateWeight<T> {
/// The range of component `i` is `[0, 1000000]`.
fn addition(_i: u32, ) -> Weight {
// Minimum execution time: 108 nanoseconds.
Weight::from_ref_time(137_610 as u64)
// Proof Size summary in bytes:
// Measured: `0`
// Estimated: `0`
// Minimum execution time: 138 nanoseconds.
Weight::from_ref_time(199_805)
}
/// The range of component `i` is `[0, 1000000]`.
fn subtraction(_i: u32, ) -> Weight {
// Minimum execution time: 104 nanoseconds.
Weight::from_ref_time(133_508 as u64)
// Proof Size summary in bytes:
// Measured: `0`
// Estimated: `0`
// Minimum execution time: 142 nanoseconds.
Weight::from_ref_time(201_435)
}
/// The range of component `i` is `[0, 1000000]`.
fn multiplication(_i: u32, ) -> Weight {
// Minimum execution time: 110 nanoseconds.
Weight::from_ref_time(140_230 as u64)
// Proof Size summary in bytes:
// Measured: `0`
// Estimated: `0`
// Minimum execution time: 138 nanoseconds.
Weight::from_ref_time(207_037)
}
/// The range of component `i` is `[0, 1000000]`.
fn division(_i: u32, ) -> Weight {
// Minimum execution time: 96 nanoseconds.
Weight::from_ref_time(136_059 as u64)
// Proof Size summary in bytes:
// Measured: `0`
// Estimated: `0`
// Minimum execution time: 151 nanoseconds.
Weight::from_ref_time(205_150)
}
/// The range of component `i` is `[0, 100]`.
fn hashing(_i: u32, ) -> Weight {
// Minimum execution time: 21_804_747 nanoseconds.
Weight::from_ref_time(22_013_681_386 as u64)
fn hashing() -> Weight {
// Proof Size summary in bytes:
// Measured: `0`
// Estimated: `0`
// Minimum execution time: 21_950_884 nanoseconds.
Weight::from_ref_time(21_994_001_000)
}
/// The range of component `i` is `[0, 100]`.
fn sr25519_verification(i: u32, ) -> Weight {
// Minimum execution time: 136 nanoseconds.
Weight::from_ref_time(156_000 as u64)
// Standard Error: 4_531
.saturating_add(Weight::from_ref_time(46_817_640 as u64).saturating_mul(i as u64))
}
// Storage: Skipped Metadata (r:0 w:0)
/// The range of component `i` is `[0, 1000]`.
fn storage_read(i: u32, ) -> Weight {
// Minimum execution time: 125 nanoseconds.
Weight::from_ref_time(135_000 as u64)
// Standard Error: 3_651
.saturating_add(Weight::from_ref_time(2_021_172 as u64).saturating_mul(i as u64))
.saturating_add(T::DbWeight::get().reads((1 as u64).saturating_mul(i as u64)))
}
// Storage: Skipped Metadata (r:0 w:0)
/// The range of component `i` is `[0, 1000]`.
fn storage_write(i: u32, ) -> Weight {
// Minimum execution time: 120 nanoseconds.
Weight::from_ref_time(131_000 as u64)
// Standard Error: 348
.saturating_add(Weight::from_ref_time(377_243 as u64).saturating_mul(i as u64))
.saturating_add(T::DbWeight::get().writes((1 as u64).saturating_mul(i as u64)))
// Proof Size summary in bytes:
// Measured: `0`
// Estimated: `0`
// Minimum execution time: 168 nanoseconds.
Weight::from_ref_time(1_680_898)
// Standard Error: 10_291
.saturating_add(Weight::from_ref_time(46_867_301).saturating_mul(i.into()))
}
}
@@ -116,52 +114,51 @@ impl<T: frame_system::Config> WeightInfo for SubstrateWeight<T> {
impl WeightInfo for () {
/// The range of component `i` is `[0, 1000000]`.
fn addition(_i: u32, ) -> Weight {
// Minimum execution time: 108 nanoseconds.
Weight::from_ref_time(137_610 as u64)
// Proof Size summary in bytes:
// Measured: `0`
// Estimated: `0`
// Minimum execution time: 138 nanoseconds.
Weight::from_ref_time(199_805)
}
/// The range of component `i` is `[0, 1000000]`.
fn subtraction(_i: u32, ) -> Weight {
// Minimum execution time: 104 nanoseconds.
Weight::from_ref_time(133_508 as u64)
// Proof Size summary in bytes:
// Measured: `0`
// Estimated: `0`
// Minimum execution time: 142 nanoseconds.
Weight::from_ref_time(201_435)
}
/// The range of component `i` is `[0, 1000000]`.
fn multiplication(_i: u32, ) -> Weight {
// Minimum execution time: 110 nanoseconds.
Weight::from_ref_time(140_230 as u64)
// Proof Size summary in bytes:
// Measured: `0`
// Estimated: `0`
// Minimum execution time: 138 nanoseconds.
Weight::from_ref_time(207_037)
}
/// The range of component `i` is `[0, 1000000]`.
fn division(_i: u32, ) -> Weight {
// Minimum execution time: 96 nanoseconds.
Weight::from_ref_time(136_059 as u64)
// Proof Size summary in bytes:
// Measured: `0`
// Estimated: `0`
// Minimum execution time: 151 nanoseconds.
Weight::from_ref_time(205_150)
}
/// The range of component `i` is `[0, 100]`.
fn hashing(_i: u32, ) -> Weight {
// Minimum execution time: 21_804_747 nanoseconds.
Weight::from_ref_time(22_013_681_386 as u64)
fn hashing() -> Weight {
// Proof Size summary in bytes:
// Measured: `0`
// Estimated: `0`
// Minimum execution time: 21_950_884 nanoseconds.
Weight::from_ref_time(21_994_001_000)
}
/// The range of component `i` is `[0, 100]`.
fn sr25519_verification(i: u32, ) -> Weight {
// Minimum execution time: 136 nanoseconds.
Weight::from_ref_time(156_000 as u64)
// Standard Error: 4_531
.saturating_add(Weight::from_ref_time(46_817_640 as u64).saturating_mul(i as u64))
}
// Storage: Skipped Metadata (r:0 w:0)
/// The range of component `i` is `[0, 1000]`.
fn storage_read(i: u32, ) -> Weight {
// Minimum execution time: 125 nanoseconds.
Weight::from_ref_time(135_000 as u64)
// Standard Error: 3_651
.saturating_add(Weight::from_ref_time(2_021_172 as u64).saturating_mul(i as u64))
.saturating_add(RocksDbWeight::get().reads((1 as u64).saturating_mul(i as u64)))
}
// Storage: Skipped Metadata (r:0 w:0)
/// The range of component `i` is `[0, 1000]`.
fn storage_write(i: u32, ) -> Weight {
// Minimum execution time: 120 nanoseconds.
Weight::from_ref_time(131_000 as u64)
// Standard Error: 348
.saturating_add(Weight::from_ref_time(377_243 as u64).saturating_mul(i as u64))
.saturating_add(RocksDbWeight::get().writes((1 as u64).saturating_mul(i as u64)))
// Proof Size summary in bytes:
// Measured: `0`
// Estimated: `0`
// Minimum execution time: 168 nanoseconds.
Weight::from_ref_time(1_680_898)
// Standard Error: 10_291
.saturating_add(Weight::from_ref_time(46_867_301).saturating_mul(i.into()))
}
}