Fix Compiler Warnings (new rustc) (#8907)

* 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>
This commit is contained in:
Shawn Tabrizi
2021-05-27 01:52:05 -04:00
committed by GitHub
parent 053be60b82
commit fa89414bba
6 changed files with 141 additions and 97 deletions
+49 -46
View File
@@ -139,7 +139,6 @@ fn construct_block<E: Externalities>(
(Block { header, extrinsics }.encode(), hash.into())
}
fn test_blocks(genesis_config: &GenesisConfig, executor: &NativeExecutor<Executor>)
-> Vec<(Vec<u8>, Hash)>
{
@@ -147,7 +146,7 @@ fn test_blocks(genesis_config: &GenesisConfig, executor: &NativeExecutor<Executo
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| {
@@ -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 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::<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 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,
);
},
);
}
}
@@ -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();
@@ -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();
@@ -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,
};
-2
View File
@@ -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 {
(
+4 -4
View File
@@ -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)?;
@@ -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>() {
+79 -36
View File
@@ -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<u8>) {
}
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::<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)),
);
}
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);