Skip to content
This repository has been archived by the owner on Nov 15, 2023. It is now read-only.

Commit

Permalink
Fix Compiler Warnings (new rustc) (#8907)
Browse files Browse the repository at this point in the history
* unused mmr

* more unused

* dyn in executor

* remove `doc(inline)`

* fix dyn for sp-api-test

* update benchmarks

* Update primitives/core/benches/bench.rs

* Update primitives/core/benches/bench.rs

* update another bench

* fix benchmark?

Co-authored-by: adoerr <0xad@gmx.net>
  • Loading branch information
shawntabrizi and adoerr committed May 27, 2021
1 parent 25db73e commit 1cbf0e1
Show file tree
Hide file tree
Showing 6 changed files with 144 additions and 100 deletions.
103 changes: 53 additions & 50 deletions bin/node/executor/benches/bench.rs
Original file line number Diff line number Diff line change
Expand Up @@ -139,15 +139,14 @@ fn construct_block<E: Externalities>(
(Block { header, extrinsics }.encode(), hash.into())
}


fn test_blocks(genesis_config: &GenesisConfig, executor: &NativeExecutor<Executor>)
-> Vec<(Vec<u8>, Hash)>
{
let mut test_ext = new_test_ext(genesis_config);
let mut block1_extrinsics = vec![
CheckedExtrinsic {
signed: None,
function: Call::Timestamp(pallet_timestamp::Call::set(42 * 1000)),
function: Call::Timestamp(pallet_timestamp::Call::set(0)),
},
];
block1_extrinsics.extend((0..20).map(|i| {
Expand All @@ -168,52 +167,56 @@ fn test_blocks(genesis_config: &GenesisConfig, executor: &NativeExecutor<Executo
}

fn bench_execute_block(c: &mut Criterion) {
c.bench_function_over_inputs(
"execute blocks",
|b, strategy| {
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),
};

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,
};

// 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 blocks = test_blocks(&genesis_config, &executor);

b.iter_batched_ref(
|| new_test_ext(&genesis_config),
|test_ext| {
for block in blocks.iter() {
executor.call::<NeverNativeValue, fn() -> _>(
&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 mut group = c.benchmark_group("execute blocks");
let execution_methods = vec![
ExecutionMethod::Native,
ExecutionMethod::Wasm(WasmExecutionMethod::Interpreted),
#[cfg(feature = "wasmtime")]
ExecutionMethod::Wasm(WasmExecutionMethod::Compiled),
];

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),
};

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,
};

// 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 blocks = test_blocks(&genesis_config, &executor);

b.iter_batched_ref(
|| new_test_ext(&genesis_config),
|test_ext| {
for block in blocks.iter() {
executor.call::<NeverNativeValue, fn() -> _>(
&mut test_ext.ext(),
&runtime_code,
"Core_execute_block",
&block.0,
use_native,
None,
).0.unwrap();
}
},
BatchSize::LargeInput,
);
},
);
}
}
6 changes: 3 additions & 3 deletions client/executor/src/wasm_runtime.rs
Original file line number Diff line number Diff line change
Expand Up @@ -492,7 +492,7 @@ mod tests {
authoring_version: 1,
spec_version: 1,
impl_version: 1,
apis: sp_api::create_apis_vec!([(Core::<Block>::ID, 1)]),
apis: sp_api::create_apis_vec!([(<dyn Core::<Block>>::ID, 1)]),
};

let version = decode_version(&old_runtime_version.encode()).unwrap();
Expand All @@ -507,7 +507,7 @@ mod tests {
authoring_version: 1,
spec_version: 1,
impl_version: 1,
apis: sp_api::create_apis_vec!([(Core::<Block>::ID, 3)]),
apis: sp_api::create_apis_vec!([(<dyn Core::<Block>>::ID, 3)]),
};

decode_version(&old_runtime_version.encode()).unwrap_err();
Expand All @@ -521,7 +521,7 @@ mod tests {
authoring_version: 1,
spec_version: 1,
impl_version: 1,
apis: sp_api::create_apis_vec!([(Core::<Block>::ID, 3)]),
apis: sp_api::create_apis_vec!([(<dyn Core::<Block>>::ID, 3)]),
transaction_version: 3,
};

Expand Down
2 changes: 0 additions & 2 deletions frame/support/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 )* ) => {
Expand All @@ -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 {
(
Expand Down
8 changes: 4 additions & 4 deletions frame/utility/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,14 +41,14 @@ pub mod example {

decl_module! {
pub struct Module<T: Config> for enum Call where origin: <T as frame_system::Config>::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<Weight>,
) -> DispatchResultWithPostInfo {
let _ = ensure_signed(origin)?;
Expand Down
12 changes: 6 additions & 6 deletions primitives/api/test/tests/decl_and_impl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -156,19 +156,19 @@ fn test_client_side_function_signature() {

#[test]
fn check_runtime_api_info() {
assert_eq!(&Api::<Block>::ID, &runtime_decl_for_Api::ID);
assert_eq!(Api::<Block>::VERSION, runtime_decl_for_Api::VERSION);
assert_eq!(Api::<Block>::VERSION, 1);
assert_eq!(&<dyn Api::<Block>>::ID, &runtime_decl_for_Api::ID);
assert_eq!(<dyn Api::<Block>>::VERSION, runtime_decl_for_Api::VERSION);
assert_eq!(<dyn Api::<Block>>::VERSION, 1);

assert_eq!(
ApiWithCustomVersion::<Block>::VERSION,
<dyn ApiWithCustomVersion::<Block>>::VERSION,
runtime_decl_for_ApiWithCustomVersion::VERSION,
);
assert_eq!(
&ApiWithCustomVersion::<Block>::ID,
&<dyn ApiWithCustomVersion::<Block>>::ID,
&runtime_decl_for_ApiWithCustomVersion::ID,
);
assert_eq!(ApiWithCustomVersion::<Block>::VERSION, 2);
assert_eq!(<dyn ApiWithCustomVersion::<Block>>::VERSION, 2);
}

fn check_runtime_api_versions_contains<T: RuntimeApiInfo + ?Sized>() {
Expand Down
113 changes: 78 additions & 35 deletions primitives/core/benches/bench.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};

Expand Down Expand Up @@ -49,87 +46,133 @@ fn bench_twox_128(b: &mut Bencher, key: &Vec<u8>) {
}

fn bench_hash_128_fix_size(c: &mut Criterion) {
let mut group = c.benchmark_group("fix size hashing");

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];

c.bench_functions("fixed size hashing", fns, key);
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::<u8>())
.collect::<Vec<_>>();
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::<u8>())
.collect::<Vec<_>>();
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::<u8>())
.collect::<Vec<_>>();
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::<u8>())
.collect::<Vec<_>>();
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::<u8>())
.collect::<Vec<_>>();
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::<u8>())
.collect::<Vec<_>>();
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)),
);
}

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
group.finish();
}

criterion_group!(
benches,
bench_hash_128_fix_size,
bench_hash_128_dyn_size,
bench_ed25519,
bench_sr25519,
bench_ecdsa,
);
criterion_main!(benches);

0 comments on commit 1cbf0e1

Please sign in to comment.