diff --git a/substrate/bin/node/executor/benches/bench.rs b/substrate/bin/node/executor/benches/bench.rs index 554e6c4af4..d21aedd1d1 100644 --- a/substrate/bin/node/executor/benches/bench.rs +++ b/substrate/bin/node/executor/benches/bench.rs @@ -139,7 +139,6 @@ fn construct_block( (Block { header, extrinsics }.encode(), hash.into()) } - fn test_blocks(genesis_config: &GenesisConfig, executor: &NativeExecutor) -> Vec<(Vec, Hash)> { @@ -147,7 +146,7 @@ fn test_blocks(genesis_config: &GenesisConfig, executor: &NativeExecutor (true, WasmExecutionMethod::Interpreted), - ExecutionMethod::Wasm(wasm_method) => (false, *wasm_method), - }; + let mut group = c.benchmark_group("execute blocks"); + let execution_methods = vec![ + ExecutionMethod::Native, + ExecutionMethod::Wasm(WasmExecutionMethod::Interpreted), + #[cfg(feature = "wasmtime")] + ExecutionMethod::Wasm(WasmExecutionMethod::Compiled), + ]; - let executor = NativeExecutor::new(wasm_method, None, 8); - let runtime_code = RuntimeCode { - code_fetcher: &sp_core::traits::WrappedRuntimeCode(compact_code_unwrap().into()), - hash: vec![1, 2, 3], - heap_pages: None, - }; + for strategy in execution_methods { + group.bench_function( + format!("{:?}", strategy), + |b| { + let genesis_config = node_testing::genesis::config(false, Some(compact_code_unwrap())); + let (use_native, wasm_method) = match strategy { + ExecutionMethod::Native => (true, WasmExecutionMethod::Interpreted), + ExecutionMethod::Wasm(wasm_method) => (false, wasm_method), + }; - // Get the runtime version to initialize the runtimes cache. - { - let mut test_ext = new_test_ext(&genesis_config); - executor.runtime_version(&mut test_ext.ext(), &runtime_code).unwrap(); - } + let executor = NativeExecutor::new(wasm_method, None, 8); + let runtime_code = RuntimeCode { + code_fetcher: &sp_core::traits::WrappedRuntimeCode(compact_code_unwrap().into()), + hash: vec![1, 2, 3], + heap_pages: None, + }; - let blocks = test_blocks(&genesis_config, &executor); + // Get the runtime version to initialize the runtimes cache. + { + let mut test_ext = new_test_ext(&genesis_config); + executor.runtime_version(&mut test_ext.ext(), &runtime_code).unwrap(); + } - b.iter_batched_ref( - || new_test_ext(&genesis_config), - |test_ext| { - for block in blocks.iter() { - executor.call:: _>( - &mut test_ext.ext(), - &runtime_code, - "Core_execute_block", - &block.0, - use_native, - None, - ).0.unwrap(); - } - }, - BatchSize::LargeInput, - ); - }, - vec![ - ExecutionMethod::Native, - ExecutionMethod::Wasm(WasmExecutionMethod::Interpreted), - #[cfg(feature = "wasmtime")] - ExecutionMethod::Wasm(WasmExecutionMethod::Compiled), - ], - ); + let blocks = test_blocks(&genesis_config, &executor); + + b.iter_batched_ref( + || new_test_ext(&genesis_config), + |test_ext| { + for block in blocks.iter() { + executor.call:: _>( + &mut test_ext.ext(), + &runtime_code, + "Core_execute_block", + &block.0, + use_native, + None, + ).0.unwrap(); + } + }, + BatchSize::LargeInput, + ); + }, + ); + } } diff --git a/substrate/client/executor/src/wasm_runtime.rs b/substrate/client/executor/src/wasm_runtime.rs index 23e88f9440..6c13150613 100644 --- a/substrate/client/executor/src/wasm_runtime.rs +++ b/substrate/client/executor/src/wasm_runtime.rs @@ -492,7 +492,7 @@ mod tests { authoring_version: 1, spec_version: 1, impl_version: 1, - apis: sp_api::create_apis_vec!([(Core::::ID, 1)]), + apis: sp_api::create_apis_vec!([(>::ID, 1)]), }; let version = decode_version(&old_runtime_version.encode()).unwrap(); @@ -507,7 +507,7 @@ mod tests { authoring_version: 1, spec_version: 1, impl_version: 1, - apis: sp_api::create_apis_vec!([(Core::::ID, 3)]), + apis: sp_api::create_apis_vec!([(>::ID, 3)]), }; decode_version(&old_runtime_version.encode()).unwrap_err(); @@ -521,7 +521,7 @@ mod tests { authoring_version: 1, spec_version: 1, impl_version: 1, - apis: sp_api::create_apis_vec!([(Core::::ID, 3)]), + apis: sp_api::create_apis_vec!([(>::ID, 3)]), transaction_version: 3, }; diff --git a/substrate/frame/support/src/lib.rs b/substrate/frame/support/src/lib.rs index 911373bfad..edbc69df26 100644 --- a/substrate/frame/support/src/lib.rs +++ b/substrate/frame/support/src/lib.rs @@ -397,7 +397,6 @@ macro_rules! parameter_types { } #[cfg(not(feature = "std"))] -#[doc(inline)] #[macro_export] macro_rules! parameter_types_impl_thread_local { ( $( $any:tt )* ) => { @@ -406,7 +405,6 @@ macro_rules! parameter_types_impl_thread_local { } #[cfg(feature = "std")] -#[doc(inline)] #[macro_export] macro_rules! parameter_types_impl_thread_local { ( diff --git a/substrate/frame/utility/src/tests.rs b/substrate/frame/utility/src/tests.rs index 1828418bd7..6d9db2f0c6 100644 --- a/substrate/frame/utility/src/tests.rs +++ b/substrate/frame/utility/src/tests.rs @@ -41,14 +41,14 @@ pub mod example { decl_module! { pub struct Module for enum Call where origin: ::Origin { - #[weight = *weight] - fn noop(_origin, weight: Weight) { } + #[weight = *_weight] + fn noop(_origin, _weight: Weight) { } - #[weight = *start_weight] + #[weight = *_start_weight] fn foobar( origin, err: bool, - start_weight: Weight, + _start_weight: Weight, end_weight: Option, ) -> DispatchResultWithPostInfo { let _ = ensure_signed(origin)?; diff --git a/substrate/primitives/api/test/tests/decl_and_impl.rs b/substrate/primitives/api/test/tests/decl_and_impl.rs index 1f7ccf2712..54fb37133f 100644 --- a/substrate/primitives/api/test/tests/decl_and_impl.rs +++ b/substrate/primitives/api/test/tests/decl_and_impl.rs @@ -156,19 +156,19 @@ fn test_client_side_function_signature() { #[test] fn check_runtime_api_info() { - assert_eq!(&Api::::ID, &runtime_decl_for_Api::ID); - assert_eq!(Api::::VERSION, runtime_decl_for_Api::VERSION); - assert_eq!(Api::::VERSION, 1); + assert_eq!(&>::ID, &runtime_decl_for_Api::ID); + assert_eq!(>::VERSION, runtime_decl_for_Api::VERSION); + assert_eq!(>::VERSION, 1); assert_eq!( - ApiWithCustomVersion::::VERSION, + >::VERSION, runtime_decl_for_ApiWithCustomVersion::VERSION, ); assert_eq!( - &ApiWithCustomVersion::::ID, + &>::ID, &runtime_decl_for_ApiWithCustomVersion::ID, ); - assert_eq!(ApiWithCustomVersion::::VERSION, 2); + assert_eq!(>::VERSION, 2); } fn check_runtime_api_versions_contains() { diff --git a/substrate/primitives/core/benches/bench.rs b/substrate/primitives/core/benches/bench.rs index d7c127320f..77680d53be 100644 --- a/substrate/primitives/core/benches/bench.rs +++ b/substrate/primitives/core/benches/bench.rs @@ -12,13 +12,10 @@ // See the License for the specific language governing permissions and // limitations under the License. - - #[macro_use] extern crate criterion; -use criterion::{Criterion, black_box, Bencher, Fun}; -use std::time::Duration; +use criterion::{Criterion, black_box, Bencher, BenchmarkId}; use sp_core::crypto::Pair as _; use sp_core::hashing::{twox_128, blake2_128}; @@ -49,87 +46,133 @@ fn bench_twox_128(b: &mut Bencher, key: &Vec) { } fn bench_hash_128_fix_size(c: &mut Criterion) { - let key = get_key(MAX_KEY_SIZE); - let blake_fn = Fun::new("blake2_128", bench_blake2_128); - let twox_fn = Fun::new("twox_128", bench_twox_128); - let fns = vec![blake_fn, twox_fn]; + let mut group = c.benchmark_group("fix size hashing"); - c.bench_functions("fixed size hashing", fns, key); + let key = get_key(MAX_KEY_SIZE); + + group.bench_with_input("blake2_128", &key, bench_blake2_128); + group.bench_with_input("twox_128", &key, bench_twox_128); + + group.finish(); } fn bench_hash_128_dyn_size(c: &mut Criterion) { - let mut keys = Vec::new(); + let mut group = c.benchmark_group("dyn size hashing"); + for i in (2..MAX_KEY_SIZE).step_by(4) { - keys.push(get_key(i).clone()) + let key = get_key(i); + + group.bench_with_input( + BenchmarkId::new("blake2_128", format!("{}", i)), + &key, + bench_blake2_128, + ); + group.bench_with_input( + BenchmarkId::new("twox_128", format!("{}", i)), + &key, + bench_twox_128, + ); } - c.bench_function_over_inputs("dyn size hashing - blake2", |b, key| bench_blake2_128(b, &key), keys.clone()); - c.bench_function_over_inputs("dyn size hashing - twox", |b, key| bench_twox_128(b, &key), keys); + group.finish(); } fn bench_ed25519(c: &mut Criterion) { - c.bench_function_over_inputs("signing - ed25519", |b, &msg_size| { + let mut group = c.benchmark_group("ed25519"); + + for msg_size in vec![32, 1024, 1024 * 1024] { let msg = (0..msg_size) .map(|_| rand::random::()) .collect::>(); let key = sp_core::ed25519::Pair::generate().0; - b.iter(|| key.sign(&msg)) - }, vec![32, 1024, 1024 * 1024]); + group.bench_function( + BenchmarkId::new("signing", format!("{}", msg_size)), + |b| b.iter(|| key.sign(&msg)), + ); + } - c.bench_function_over_inputs("verifying - ed25519", |b, &msg_size| { + for msg_size in vec![32, 1024, 1024 * 1024] { let msg = (0..msg_size) .map(|_| rand::random::()) .collect::>(); let key = sp_core::ed25519::Pair::generate().0; let sig = key.sign(&msg); let public = key.public(); - b.iter(|| sp_core::ed25519::Pair::verify(&sig, &msg, &public)) - }, vec![32, 1024, 1024 * 1024]); + group.bench_function( + BenchmarkId::new("verifying", format!("{}", msg_size)), + |b| b.iter(|| sp_core::ed25519::Pair::verify(&sig, &msg, &public)), + ); + } + + group.finish(); } fn bench_sr25519(c: &mut Criterion) { - c.bench_function_over_inputs("signing - sr25519", |b, &msg_size| { + let mut group = c.benchmark_group("sr25519"); + + for msg_size in vec![32, 1024, 1024 * 1024] { let msg = (0..msg_size) .map(|_| rand::random::()) .collect::>(); let key = sp_core::sr25519::Pair::generate().0; - b.iter(|| key.sign(&msg)) - }, vec![32, 1024, 1024 * 1024]); + group.bench_function( + BenchmarkId::new("signing", format!("{}", msg_size)), + |b| b.iter(|| key.sign(&msg)), + ); + } - c.bench_function_over_inputs("verifying - sr25519", |b, &msg_size| { + for msg_size in vec![32, 1024, 1024 * 1024] { let msg = (0..msg_size) .map(|_| rand::random::()) .collect::>(); let key = sp_core::sr25519::Pair::generate().0; let sig = key.sign(&msg); let public = key.public(); - b.iter(|| sp_core::sr25519::Pair::verify(&sig, &msg, &public)) - }, vec![32, 1024, 1024 * 1024]); + group.bench_function( + BenchmarkId::new("verifying", format!("{}", msg_size)), + |b| b.iter(|| sp_core::sr25519::Pair::verify(&sig, &msg, &public)), + ); + } + + group.finish(); } fn bench_ecdsa(c: &mut Criterion) { - c.bench_function_over_inputs("signing - ecdsa", |b, &msg_size| { + let mut group = c.benchmark_group("ecdsa"); + + for msg_size in vec![32, 1024, 1024 * 1024] { let msg = (0..msg_size) .map(|_| rand::random::()) .collect::>(); let key = sp_core::ecdsa::Pair::generate().0; - b.iter(|| key.sign(&msg)) - }, vec![32, 1024, 1024 * 1024]); + group.bench_function( + BenchmarkId::new("signing", format!("{}", msg_size)), + |b| b.iter(|| key.sign(&msg)), + ); + } - c.bench_function_over_inputs("verifying - ecdsa", |b, &msg_size| { + for msg_size in vec![32, 1024, 1024 * 1024] { let msg = (0..msg_size) .map(|_| rand::random::()) .collect::>(); let key = sp_core::ecdsa::Pair::generate().0; let sig = key.sign(&msg); let public = key.public(); - b.iter(|| sp_core::ecdsa::Pair::verify(&sig, &msg, &public)) - }, vec![32, 1024, 1024 * 1024]); + group.bench_function( + BenchmarkId::new("verifying", format!("{}", msg_size)), + |b| b.iter(|| sp_core::ecdsa::Pair::verify(&sig, &msg, &public)), + ); + } + + group.finish(); } -criterion_group!{ - name = benches; - config = Criterion::default().warm_up_time(Duration::from_millis(500)).without_plots(); - targets = bench_hash_128_fix_size, bench_hash_128_dyn_size, bench_ed25519, bench_sr25519, bench_ecdsa -} +criterion_group!( + benches, + bench_hash_128_fix_size, + bench_hash_128_dyn_size, + bench_ed25519, + bench_sr25519, + bench_ecdsa, +); criterion_main!(benches);