Skip to content

Commit 41df5a2

Browse files
Run Benchmarking for All runtimes (#1697)
* Fixed `make bench` command Removed router benchmarking because it has some issue Removed steaming pallet benchmarking because this pallet doesn't have benchmarking and blocking the benchmarking of other pallet. * Fix asset-registry pallet * updated weights * run benchmarking for all runtimes in a single command * refactoring * run format Signed-off-by: Cheng JIANG <[email protected]> * run format Signed-off-by: Cheng JIANG <[email protected]> Co-authored-by: Ayush <> Co-authored-by: Cheng JIANG <[email protected]>
1 parent 38b0f06 commit 41df5a2

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

72 files changed

+7309
-1809
lines changed
Lines changed: 44 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,14 @@
1-
// Copyright 2021 Parallel Finance Developer.
21
// This file is part of Parallel Finance.
32

3+
// Copyright (C) 2022 Parallel Finance Developer.
4+
// SPDX-License-Identifier: Apache-2.0
5+
46
// Licensed under the Apache License, Version 2.0 (the "License");
57
// you may not use this file except in compliance with the License.
68
// You may obtain a copy of the License at
9+
//
710
// http://www.apache.org/licenses/LICENSE-2.0
8-
11+
//
912
// Unless required by applicable law or agreed to in writing, software
1013
// distributed under the License is distributed on an "AS IS" BASIS,
1114
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@@ -19,86 +22,93 @@
1922
//! EXECUTION: {{cmd.execution}}, WASM-EXECUTION: {{cmd.wasm_execution}}, CHAIN: {{cmd.chain}}, DB CACHE: {{cmd.db_cache}}
2023

2124
// Executed Command:
22-
{{#each args as |arg|~}}
25+
{{#each args as |arg|}}
2326
// {{arg}}
2427
{{/each}}
2528

29+
#![cfg_attr(rustfmt, rustfmt_skip)]
2630
#![allow(unused_parens)]
2731
#![allow(unused_imports)]
28-
#![allow(clippy::all)]
2932

30-
use frame_support::{
31-
traits::Get,
32-
weights::{constants::RocksDbWeight, Weight},
33-
};
33+
use frame_support::{traits::Get, weights::{Weight, constants::RocksDbWeight}};
3434
use sp_std::marker::PhantomData;
3535

3636
/// Weight functions needed for {{pallet}}.
3737
pub trait WeightInfo {
38-
{{~#each benchmarks as |benchmark|}}
38+
{{#each benchmarks as |benchmark|}}
3939
fn {{benchmark.name~}}
4040
(
4141
{{~#each benchmark.components as |c| ~}}
4242
{{c.name}}: u32, {{/each~}}
4343
) -> Weight;
44-
{{~/each}}
44+
{{/each}}
4545
}
4646

4747
/// Weights for {{pallet}} using the Substrate node and recommended hardware.
4848
pub struct SubstrateWeight<T>(PhantomData<T>);
49+
{{#if (eq pallet "frame_system")}}
50+
impl<T: crate::Config> WeightInfo for SubstrateWeight<T> {
51+
{{else}}
4952
impl<T: frame_system::Config> WeightInfo for SubstrateWeight<T> {
50-
{{~#each benchmarks as |benchmark|}}
53+
{{/if}}
54+
{{#each benchmarks as |benchmark|}}
55+
{{#each benchmark.comments as |comment|}}
56+
// {{comment}}
57+
{{/each}}
5158
fn {{benchmark.name~}}
5259
(
5360
{{~#each benchmark.components as |c| ~}}
5461
{{~#if (not c.is_used)}}_{{/if}}{{c.name}}: u32, {{/each~}}
5562
) -> Weight {
5663
({{underscore benchmark.base_weight}} as Weight)
57-
{{~#each benchmark.component_weight as |cw|}}
64+
{{#each benchmark.component_weight as |cw|}}
5865
// Standard Error: {{underscore cw.error}}
5966
.saturating_add(({{underscore cw.slope}} as Weight).saturating_mul({{cw.name}} as Weight))
60-
{{~/each}}
61-
{{~#if (ne benchmark.base_reads "0")}}
67+
{{/each}}
68+
{{#if (ne benchmark.base_reads "0")}}
6269
.saturating_add(T::DbWeight::get().reads({{benchmark.base_reads}} as Weight))
63-
{{~/if}}
64-
{{~#each benchmark.component_reads as |cr|}}
70+
{{/if}}
71+
{{#each benchmark.component_reads as |cr|}}
6572
.saturating_add(T::DbWeight::get().reads(({{cr.slope}} as Weight).saturating_mul({{cr.name}} as Weight)))
66-
{{~/each}}
67-
{{~#if (ne benchmark.base_writes "0")}}
73+
{{/each}}
74+
{{#if (ne benchmark.base_writes "0")}}
6875
.saturating_add(T::DbWeight::get().writes({{benchmark.base_writes}} as Weight))
69-
{{~/if}}
70-
{{~#each benchmark.component_writes as |cw|}}
76+
{{/if}}
77+
{{#each benchmark.component_writes as |cw|}}
7178
.saturating_add(T::DbWeight::get().writes(({{cw.slope}} as Weight).saturating_mul({{cw.name}} as Weight)))
72-
{{~/each}}
79+
{{/each}}
7380
}
74-
{{~/each}}
81+
{{/each}}
7582
}
7683

7784
// For backwards compatibility and tests
7885
impl WeightInfo for () {
79-
{{~#each benchmarks as |benchmark|}}
86+
{{#each benchmarks as |benchmark|}}
87+
{{#each benchmark.comments as |comment|}}
88+
// {{comment}}
89+
{{/each}}
8090
fn {{benchmark.name~}}
8191
(
8292
{{~#each benchmark.components as |c| ~}}
8393
{{~#if (not c.is_used)}}_{{/if}}{{c.name}}: u32, {{/each~}}
8494
) -> Weight {
8595
({{underscore benchmark.base_weight}} as Weight)
86-
{{~#each benchmark.component_weight as |cw|}}
96+
{{#each benchmark.component_weight as |cw|}}
8797
// Standard Error: {{underscore cw.error}}
8898
.saturating_add(({{underscore cw.slope}} as Weight).saturating_mul({{cw.name}} as Weight))
89-
{{~/each}}
90-
{{~#if (ne benchmark.base_reads "0")}}
99+
{{/each}}
100+
{{#if (ne benchmark.base_reads "0")}}
91101
.saturating_add(RocksDbWeight::get().reads({{benchmark.base_reads}} as Weight))
92-
{{~/if}}
93-
{{~#each benchmark.component_reads as |cr|}}
102+
{{/if}}
103+
{{#each benchmark.component_reads as |cr|}}
94104
.saturating_add(RocksDbWeight::get().reads(({{cr.slope}} as Weight).saturating_mul({{cr.name}} as Weight)))
95-
{{~/each}}
96-
{{~#if (ne benchmark.base_writes "0")}}
105+
{{/each}}
106+
{{#if (ne benchmark.base_writes "0")}}
97107
.saturating_add(RocksDbWeight::get().writes({{benchmark.base_writes}} as Weight))
98-
{{~/if}}
99-
{{~#each benchmark.component_writes as |cw|}}
108+
{{/if}}
109+
{{#each benchmark.component_writes as |cw|}}
100110
.saturating_add(RocksDbWeight::get().writes(({{cw.slope}} as Weight).saturating_mul({{cw.name}} as Weight)))
101-
{{~/each}}
111+
{{/each}}
102112
}
103-
{{~/each}}
113+
{{/each}}
104114
}

Makefile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ integration-test-statemine:
6767
SKIP_WASM_BUILD= cargo test -p runtime-integration-tests -- statemine::statemine --nocapture
6868

6969
.PHONY: bench
70-
bench: bench-loans bench-liquid-staking bench-amm bench-amm-router bench-crowdloans bench-bridge bench-xcm-helper bench-farming
70+
bench: bench-loans bench-liquid-staking bench-amm bench-crowdloans bench-bridge bench-xcm-helper bench-farming bench-asset-registry
7171
./scripts/benchmark.sh
7272

7373
.PHONY: bench-farming
@@ -105,7 +105,7 @@ bench-amm-router:
105105

106106
.PHONY: bench-streaming
107107
bench-streaming:
108-
cargo run --release --features runtime-benchmarks -- benchmark pallet --chain=$(CHAIN) --execution=wasm --wasm-execution=compiled --pallet=pallet-streaming --extrinsic='*' --steps=50 --repeat=20 --heap-pages=4096 --template=./.maintain/frame-weight-template.hbs --output=./pallets/stream/src/weights.rs
108+
cargo run --release --features runtime-benchmarks -- benchmark pallet --chain=$(CHAIN) --execution=wasm --wasm-execution=compiled --pallet=pallet-streaming --extrinsic='*' --steps=50 --repeat=20 --heap-pages=4096 --template=./.maintain/frame-weight-template.hbs --output=./pallets/streaming/src/weights.rs
109109

110110
.PHONY: bench-asset-registry
111111
bench-asset-registry:

node/parallel/src/command.rs

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -345,19 +345,15 @@ pub fn run() -> Result<()> {
345345
let runner = cli.create_runner(cmd)?;
346346
let chain_spec = &runner.config().chain_spec;
347347

348+
set_default_ss58_version(chain_spec);
348349
switch_runtime!(chain_spec, {
349350
match cmd {
350351
BenchmarkCmd::Pallet(cmd) => {
351352
if cfg!(feature = "runtime-benchmarks") {
352-
let runner = cli.create_runner(cmd)?;
353-
let chain_spec = &runner.config().chain_spec;
354-
355-
set_default_ss58_version(chain_spec);
356-
357353
runner.sync_run(|config| cmd.run::<Block, Executor>(config))
358354
} else {
359355
Err("Benchmarking wasn't enabled when building the node. \
360-
You can enable it with `--features runtime-benchmarks`."
356+
You can enable it with `--features runtime-benchmarks`."
361357
.into())
362358
}
363359
}

pallets/amm/src/weights.rs

Lines changed: 67 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
// This file is part of Substrate.
22

3-
// Copyright (C) 2021 Parity Technologies (UK) Ltd.
3+
// Copyright (C) 2022 Parity Technologies (UK) Ltd.
44
// SPDX-License-Identifier: Apache-2.0
55

66
// Licensed under the Apache License, Version 2.0 (the "License");
@@ -18,13 +18,14 @@
1818
//! Autogenerated weights for pallet_amm
1919
//!
2020
//! THIS FILE WAS AUTO-GENERATED USING THE SUBSTRATE BENCHMARK CLI VERSION 4.0.0-dev
21-
//! DATE: 2021-10-16, STEPS: `50`, REPEAT: 20, LOW RANGE: `[]`, HIGH RANGE: `[]`
22-
//! EXECUTION: Some(Wasm), WASM-EXECUTION: Compiled, CHAIN: Some("parallel"), DB CACHE: 128
21+
//! DATE: 2022-05-02, STEPS: `50`, REPEAT: 20, LOW RANGE: `[]`, HIGH RANGE: `[]`
22+
//! EXECUTION: Some(Wasm), WASM-EXECUTION: Compiled, CHAIN: Some("kerria-dev"), DB CACHE: 1024
2323
2424
// Executed Command:
25-
// ./target/release/parallel
25+
// target/release/parallel
2626
// benchmark
27-
// --chain=parallel
27+
// pallet
28+
// --chain=kerria-dev
2829
// --execution=wasm
2930
// --wasm-execution=compiled
3031
// --pallet=pallet-amm
@@ -35,58 +36,81 @@
3536
// --template=./.maintain/frame-weight-template.hbs
3637
// --output=./pallets/amm/src/weights.rs
3738

39+
#![cfg_attr(rustfmt, rustfmt_skip)]
3840
#![allow(unused_parens)]
3941
#![allow(unused_imports)]
40-
#![allow(clippy::all)]
4142

42-
use frame_support::{
43-
traits::Get,
44-
weights::{constants::RocksDbWeight, Weight},
45-
};
43+
use frame_support::{traits::Get, weights::{Weight, constants::RocksDbWeight}};
4644
use sp_std::marker::PhantomData;
4745

4846
/// Weight functions needed for pallet_amm.
4947
pub trait WeightInfo {
50-
fn add_liquidity() -> Weight;
51-
fn remove_liquidity() -> Weight;
52-
fn create_pool() -> Weight;
48+
fn add_liquidity() -> Weight;
49+
fn remove_liquidity() -> Weight;
50+
fn create_pool() -> Weight;
5351
}
5452

5553
/// Weights for pallet_amm using the Substrate node and recommended hardware.
5654
pub struct SubstrateWeight<T>(PhantomData<T>);
5755
impl<T: frame_system::Config> WeightInfo for SubstrateWeight<T> {
58-
fn add_liquidity() -> Weight {
59-
(257_000_000 as Weight)
60-
.saturating_add(T::DbWeight::get().reads(10 as Weight))
61-
.saturating_add(T::DbWeight::get().writes(10 as Weight))
62-
}
63-
fn remove_liquidity() -> Weight {
64-
(311_000_000 as Weight)
65-
.saturating_add(T::DbWeight::get().reads(11 as Weight))
66-
.saturating_add(T::DbWeight::get().writes(11 as Weight))
67-
}
68-
fn create_pool() -> Weight {
69-
(287_000_000 as Weight)
70-
.saturating_add(T::DbWeight::get().reads(10 as Weight))
71-
.saturating_add(T::DbWeight::get().writes(11 as Weight))
72-
}
56+
// Storage: unknown [0x3a7472616e73616374696f6e5f6c6576656c3a] (r:1 w:1)
57+
// Storage: AMM Pools (r:1 w:1)
58+
// Storage: Assets Asset (r:3 w:3)
59+
// Storage: Assets Account (r:5 w:5)
60+
fn add_liquidity() -> Weight {
61+
(82_000_000 as Weight)
62+
.saturating_add(T::DbWeight::get().reads(10 as Weight))
63+
.saturating_add(T::DbWeight::get().writes(10 as Weight))
64+
}
65+
// Storage: unknown [0x3a7472616e73616374696f6e5f6c6576656c3a] (r:1 w:1)
66+
// Storage: AMM Pools (r:1 w:1)
67+
// Storage: Assets Asset (r:3 w:3)
68+
// Storage: Assets Account (r:5 w:5)
69+
fn remove_liquidity() -> Weight {
70+
(90_000_000 as Weight)
71+
.saturating_add(T::DbWeight::get().reads(10 as Weight))
72+
.saturating_add(T::DbWeight::get().writes(10 as Weight))
73+
}
74+
// Storage: unknown [0x3a7472616e73616374696f6e5f6c6576656c3a] (r:1 w:1)
75+
// Storage: AMM Pools (r:1 w:1)
76+
// Storage: Assets Asset (r:3 w:3)
77+
// Storage: Assets Account (r:6 w:6)
78+
// Storage: System Account (r:2 w:2)
79+
fn create_pool() -> Weight {
80+
(110_000_000 as Weight)
81+
.saturating_add(T::DbWeight::get().reads(13 as Weight))
82+
.saturating_add(T::DbWeight::get().writes(13 as Weight))
83+
}
7384
}
7485

7586
// For backwards compatibility and tests
7687
impl WeightInfo for () {
77-
fn add_liquidity() -> Weight {
78-
(257_000_000 as Weight)
79-
.saturating_add(RocksDbWeight::get().reads(10 as Weight))
80-
.saturating_add(RocksDbWeight::get().writes(10 as Weight))
81-
}
82-
fn remove_liquidity() -> Weight {
83-
(311_000_000 as Weight)
84-
.saturating_add(RocksDbWeight::get().reads(11 as Weight))
85-
.saturating_add(RocksDbWeight::get().writes(11 as Weight))
86-
}
87-
fn create_pool() -> Weight {
88-
(287_000_000 as Weight)
89-
.saturating_add(RocksDbWeight::get().reads(10 as Weight))
90-
.saturating_add(RocksDbWeight::get().writes(11 as Weight))
91-
}
88+
// Storage: unknown [0x3a7472616e73616374696f6e5f6c6576656c3a] (r:1 w:1)
89+
// Storage: AMM Pools (r:1 w:1)
90+
// Storage: Assets Asset (r:3 w:3)
91+
// Storage: Assets Account (r:5 w:5)
92+
fn add_liquidity() -> Weight {
93+
(82_000_000 as Weight)
94+
.saturating_add(RocksDbWeight::get().reads(10 as Weight))
95+
.saturating_add(RocksDbWeight::get().writes(10 as Weight))
96+
}
97+
// Storage: unknown [0x3a7472616e73616374696f6e5f6c6576656c3a] (r:1 w:1)
98+
// Storage: AMM Pools (r:1 w:1)
99+
// Storage: Assets Asset (r:3 w:3)
100+
// Storage: Assets Account (r:5 w:5)
101+
fn remove_liquidity() -> Weight {
102+
(90_000_000 as Weight)
103+
.saturating_add(RocksDbWeight::get().reads(10 as Weight))
104+
.saturating_add(RocksDbWeight::get().writes(10 as Weight))
105+
}
106+
// Storage: unknown [0x3a7472616e73616374696f6e5f6c6576656c3a] (r:1 w:1)
107+
// Storage: AMM Pools (r:1 w:1)
108+
// Storage: Assets Asset (r:3 w:3)
109+
// Storage: Assets Account (r:6 w:6)
110+
// Storage: System Account (r:2 w:2)
111+
fn create_pool() -> Weight {
112+
(110_000_000 as Weight)
113+
.saturating_add(RocksDbWeight::get().reads(13 as Weight))
114+
.saturating_add(RocksDbWeight::get().writes(13 as Weight))
115+
}
92116
}

pallets/asset-registry/src/lib.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,12 +25,12 @@ pub mod mock;
2525
#[cfg(test)]
2626
pub mod tests;
2727
pub mod weights;
28-
2928
pub use pallet::*;
29+
pub use weights::WeightInfo;
3030

3131
#[pallet]
3232
pub mod pallet {
33-
use crate::weights::WeightInfo;
33+
use super::*;
3434
use frame_support::pallet_prelude::*;
3535
use frame_system::pallet_prelude::*;
3636
use parity_scale_codec::HasCompact;

0 commit comments

Comments
 (0)