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

Commit c181160

Browse files
shawntabriziParity Benchmarking Bot
and
Parity Benchmarking Bot
authored
Refactor Benchmarks for Less Wasm Memory Usage (#9373)
* extract repeat out of benchmark * remove r * unused * cargo run --quiet --release --features=runtime-benchmarks --manifest-path=bin/node/cli/Cargo.toml -- benchmark --chain=dev --steps=50 --repeat=20 --pallet=pallet_balances --extrinsic=* --execution=wasm --wasm-execution=compiled --heap-pages=4096 --output=./frame/balances/src/weights.rs --template=./.maintain/frame-weight-template.hbs * cargo run --quiet --release --features=runtime-benchmarks --manifest-path=bin/node/cli/Cargo.toml -- benchmark --chain=dev --steps=50 --repeat=20 --pallet=pallet_balances --extrinsic=* --execution=wasm --wasm-execution=compiled --heap-pages=4096 --output=./frame/balances/src/weights.rs --template=./.maintain/frame-weight-template.hbs * cargo run --quiet --release --features=runtime-benchmarks --manifest-path=bin/node/cli/Cargo.toml -- benchmark --chain=dev --steps=50 --repeat=20 --pallet=pallet_staking --extrinsic=* --execution=wasm --wasm-execution=compiled --heap-pages=4096 --output=./frame/staking/src/weights.rs --template=./.maintain/frame-weight-template.hbs * use linked map to keep order * cargo run --quiet --release --features=runtime-benchmarks --manifest-path=bin/node/cli/Cargo.toml -- benchmark --chain=dev --steps=50 --repeat=20 --pallet=pallet_balances --extrinsic=* --execution=wasm --wasm-execution=compiled --heap-pages=4096 --output=./frame/balances/src/weights.rs --template=./.maintain/frame-weight-template.hbs * Delete pallet_balances.rs * Delete out * cargo run --quiet --release --features=runtime-benchmarks --manifest-path=bin/node/cli/Cargo.toml -- benchmark --chain=dev --steps=50 --repeat=20 --pallet=pallet_staking --extrinsic=* --execution=wasm --wasm-execution=compiled --heap-pages=4096 --output=./frame/staking/src/weights.rs --template=./.maintain/frame-weight-template.hbs * steps and repeat to tuple (current_*, total_*) * idea for list command * fmt * use benchmark list in cli * handle steps in cli * move log update to cli * fmt * remove old todo * line width * cargo run --quiet --release --features=runtime-benchmarks --manifest-path=bin/node/cli/Cargo.toml -- benchmark --chain=dev --steps=50 --repeat=20 --pallet=pallet_balances --extrinsic=* --execution=wasm --wasm-execution=compiled --heap-pages=4096 --output=./frame/balances/src/weights.rs --template=./.maintain/frame-weight-template.hbs * benchmark metadata function * don't need this warm up * cargo run --quiet --release --features=runtime-benchmarks --manifest-path=bin/node/cli/Cargo.toml -- benchmark --chain=dev --steps=50 --repeat=20 --pallet=pallet_balances --extrinsic=* --execution=wasm --wasm-execution=compiled --heap-pages=4096 --output=./frame/balances/src/weights.rs --template=./.maintain/frame-weight-template.hbs * fix warnings * fix node-template * fix * fmt * line width * cargo run --quiet --release --features=runtime-benchmarks --manifest-path=bin/node/cli/Cargo.toml -- benchmark --chain=dev --steps=50 --repeat=20 --pallet=pallet_staking --extrinsic=* --execution=wasm --wasm-execution=compiled --heap-pages=4096 --output=./frame/staking/src/weights.rs --template=./.maintain/frame-weight-template.hbs * improve docs * improve cli * fix format * fix bug? * Revert "fix bug?" This reverts commit 8051bf1. * skip frame-metadata * extract repeat out of benchmark * remove r * cargo run --quiet --release --features=runtime-benchmarks --manifest-path=bin/node/cli/Cargo.toml -- benchmark --chain=dev --steps=50 --repeat=20 --pallet=pallet_balances --extrinsic=* --execution=wasm --wasm-execution=compiled --heap-pages=4096 --output=./frame/balances/src/weights.rs --template=./.maintain/frame-weight-template.hbs * cargo run --quiet --release --features=runtime-benchmarks --manifest-path=bin/node/cli/Cargo.toml -- benchmark --chain=dev --steps=50 --repeat=20 --pallet=pallet_balances --extrinsic=* --execution=wasm --wasm-execution=compiled --heap-pages=4096 --output=./frame/balances/src/weights.rs --template=./.maintain/frame-weight-template.hbs * cargo run --quiet --release --features=runtime-benchmarks --manifest-path=bin/node/cli/Cargo.toml -- benchmark --chain=dev --steps=50 --repeat=20 --pallet=pallet_staking --extrinsic=* --execution=wasm --wasm-execution=compiled --heap-pages=4096 --output=./frame/staking/src/weights.rs --template=./.maintain/frame-weight-template.hbs * use linked map to keep order * cargo run --quiet --release --features=runtime-benchmarks --manifest-path=bin/node/cli/Cargo.toml -- benchmark --chain=dev --steps=50 --repeat=20 --pallet=pallet_balances --extrinsic=* --execution=wasm --wasm-execution=compiled --heap-pages=4096 --output=./frame/balances/src/weights.rs --template=./.maintain/frame-weight-template.hbs * Delete pallet_balances.rs * Delete out * cargo run --quiet --release --features=runtime-benchmarks --manifest-path=bin/node/cli/Cargo.toml -- benchmark --chain=dev --steps=50 --repeat=20 --pallet=pallet_staking --extrinsic=* --execution=wasm --wasm-execution=compiled --heap-pages=4096 --output=./frame/staking/src/weights.rs --template=./.maintain/frame-weight-template.hbs * steps and repeat to tuple (current_*, total_*) * idea for list command * fmt * use benchmark list in cli * handle steps in cli * move log update to cli * remove old todo * line width * cargo run --quiet --release --features=runtime-benchmarks --manifest-path=bin/node/cli/Cargo.toml -- benchmark --chain=dev --steps=50 --repeat=20 --pallet=pallet_balances --extrinsic=* --execution=wasm --wasm-execution=compiled --heap-pages=4096 --output=./frame/balances/src/weights.rs --template=./.maintain/frame-weight-template.hbs * benchmark metadata function * don't need this warm up * cargo run --quiet --release --features=runtime-benchmarks --manifest-path=bin/node/cli/Cargo.toml -- benchmark --chain=dev --steps=50 --repeat=20 --pallet=pallet_balances --extrinsic=* --execution=wasm --wasm-execution=compiled --heap-pages=4096 --output=./frame/balances/src/weights.rs --template=./.maintain/frame-weight-template.hbs * fix warnings * fix node-template * fix * fmt * line width * cargo run --quiet --release --features=runtime-benchmarks --manifest-path=bin/node/cli/Cargo.toml -- benchmark --chain=dev --steps=50 --repeat=20 --pallet=pallet_staking --extrinsic=* --execution=wasm --wasm-execution=compiled --heap-pages=4096 --output=./frame/staking/src/weights.rs --template=./.maintain/frame-weight-template.hbs * improve docs * improve cli * fix format * fix bug? * Revert "fix bug?" This reverts commit 8051bf1. * skip frame-metadata * Update .gitlab-ci.yml * fix import * Update .gitlab-ci.yml Co-authored-by: Parity Benchmarking Bot <[email protected]>
1 parent 4d28ebe commit c181160

File tree

12 files changed

+1001
-481
lines changed

12 files changed

+1001
-481
lines changed

.gitlab-ci.yml

+4-3
Original file line numberDiff line numberDiff line change
@@ -273,7 +273,7 @@ node-bench-regression-guard:
273273
CI_IMAGE: "paritytech/node-bench-regression-guard:latest"
274274
before_script: [""]
275275
script:
276-
- 'node-bench-regression-guard --reference artifacts/benches/master-*
276+
- 'node-bench-regression-guard --reference artifacts/benches/master-*
277277
--compare-with artifacts/benches/$CI_COMMIT_REF_NAME-$CI_COMMIT_SHORT_SHA'
278278

279279
cargo-check-subkey:
@@ -343,6 +343,7 @@ unleash-check:
343343
- mkdir -p target/unleash
344344
- export CARGO_TARGET_DIR=target/unleash
345345
- cargo unleash check ${CARGO_UNLEASH_PKG_DEF}
346+
allow_failure: true
346347

347348
test-frame-examples-compile-to-wasm:
348349
# into one job
@@ -578,7 +579,7 @@ build-rust-doc:
578579
- buildah push --format=v2s2 "$IMAGE_NAME:latest"
579580
after_script:
580581
- buildah logout "$IMAGE_NAME"
581-
# pass artifacts to the trigger-simnet job
582+
# pass artifacts to the trigger-simnet job
582583
- echo "IMAGE_NAME=${IMAGE_NAME}" | tee -a ./artifacts/$PRODUCT/build.env
583584
- IMAGE_TAG="$(cat ./artifacts/$PRODUCT/VERSION)"
584585
- echo "IMAGE_TAG=${IMAGE_TAG}" | tee -a ./artifacts/$PRODUCT/build.env
@@ -713,7 +714,7 @@ trigger-simnet:
713714
- if: $CI_COMMIT_REF_NAME == "master"
714715
needs:
715716
- job: publish-docker-substrate
716-
# `build.env` brings here `$IMAGE_NAME` and `$IMAGE_TAG` (`$VERSION` here,
717+
# `build.env` brings here `$IMAGE_NAME` and `$IMAGE_TAG` (`$VERSION` here,
717718
# i.e. `2643-0.8.29-5f689e0a-6b24dc54`).
718719
variables:
719720
TRGR_PROJECT: ${CI_PROJECT_NAME}

Cargo.lock

+2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

bin/node-template/runtime/src/lib.rs

+22-8
Original file line numberDiff line numberDiff line change
@@ -446,14 +446,30 @@ impl_runtime_apis! {
446446

447447
#[cfg(feature = "runtime-benchmarks")]
448448
impl frame_benchmarking::Benchmark<Block> for Runtime {
449+
fn benchmark_metadata(extra: bool) -> (
450+
Vec<frame_benchmarking::BenchmarkList>,
451+
Vec<frame_support::traits::StorageInfo>,
452+
) {
453+
use frame_benchmarking::{list_benchmark, Benchmarking, BenchmarkList};
454+
use frame_support::traits::StorageInfoTrait;
455+
use frame_system_benchmarking::Pallet as SystemBench;
456+
457+
let mut list = Vec::<BenchmarkList>::new();
458+
459+
list_benchmark!(list, extra, frame_system, SystemBench::<Runtime>);
460+
list_benchmark!(list, extra, pallet_balances, Balances);
461+
list_benchmark!(list, extra, pallet_timestamp, Timestamp);
462+
list_benchmark!(list, extra, pallet_template, TemplateModule);
463+
464+
let storage_info = AllPalletsWithSystem::storage_info();
465+
466+
return (list, storage_info)
467+
}
468+
449469
fn dispatch_benchmark(
450470
config: frame_benchmarking::BenchmarkConfig
451-
) -> Result<
452-
(Vec<frame_benchmarking::BenchmarkBatch>, Vec<StorageInfo>),
453-
sp_runtime::RuntimeString,
454-
> {
471+
) -> Result<Vec<frame_benchmarking::BenchmarkBatch>, sp_runtime::RuntimeString> {
455472
use frame_benchmarking::{Benchmarking, BenchmarkBatch, add_benchmark, TrackedStorageKey};
456-
use frame_support::traits::StorageInfoTrait;
457473

458474
use frame_system_benchmarking::Pallet as SystemBench;
459475
impl frame_system_benchmarking::Config for Runtime {}
@@ -471,8 +487,6 @@ impl_runtime_apis! {
471487
hex_literal::hex!("26aa394eea5630e07c48ae0c9558cef780d41e5e16056765bc8461851072c9d7").to_vec().into(),
472488
];
473489

474-
let storage_info = AllPalletsWithSystem::storage_info();
475-
476490
let mut batches = Vec::<BenchmarkBatch>::new();
477491
let params = (&config, &whitelist);
478492

@@ -482,7 +496,7 @@ impl_runtime_apis! {
482496
add_benchmark!(params, batches, pallet_template, TemplateModule);
483497

484498
if batches.is_empty() { return Err("Benchmark not found for this pallet.".into()) }
485-
Ok((batches, storage_info))
499+
Ok(batches)
486500
}
487501
}
488502
}

bin/node/runtime/src/lib.rs

+55-8
Original file line numberDiff line numberDiff line change
@@ -1534,14 +1534,63 @@ impl_runtime_apis! {
15341534

15351535
#[cfg(feature = "runtime-benchmarks")]
15361536
impl frame_benchmarking::Benchmark<Block> for Runtime {
1537+
fn benchmark_metadata(extra: bool) -> (
1538+
Vec<frame_benchmarking::BenchmarkList>,
1539+
Vec<frame_support::traits::StorageInfo>,
1540+
) {
1541+
use frame_benchmarking::{list_benchmark, Benchmarking, BenchmarkList};
1542+
use frame_support::traits::StorageInfoTrait;
1543+
1544+
// Trying to add benchmarks directly to the Session Pallet caused cyclic dependency
1545+
// issues. To get around that, we separated the Session benchmarks into its own crate,
1546+
// which is why we need these two lines below.
1547+
use pallet_session_benchmarking::Pallet as SessionBench;
1548+
use pallet_offences_benchmarking::Pallet as OffencesBench;
1549+
use frame_system_benchmarking::Pallet as SystemBench;
1550+
1551+
let mut list = Vec::<BenchmarkList>::new();
1552+
1553+
list_benchmark!(list, extra, pallet_assets, Assets);
1554+
list_benchmark!(list, extra, pallet_babe, Babe);
1555+
list_benchmark!(list, extra, pallet_balances, Balances);
1556+
list_benchmark!(list, extra, pallet_bounties, Bounties);
1557+
list_benchmark!(list, extra, pallet_collective, Council);
1558+
list_benchmark!(list, extra, pallet_contracts, Contracts);
1559+
list_benchmark!(list, extra, pallet_democracy, Democracy);
1560+
list_benchmark!(list, extra, pallet_election_provider_multi_phase, ElectionProviderMultiPhase);
1561+
list_benchmark!(list, extra, pallet_elections_phragmen, Elections);
1562+
list_benchmark!(list, extra, pallet_gilt, Gilt);
1563+
list_benchmark!(list, extra, pallet_grandpa, Grandpa);
1564+
list_benchmark!(list, extra, pallet_identity, Identity);
1565+
list_benchmark!(list, extra, pallet_im_online, ImOnline);
1566+
list_benchmark!(list, extra, pallet_indices, Indices);
1567+
list_benchmark!(list, extra, pallet_lottery, Lottery);
1568+
list_benchmark!(list, extra, pallet_membership, TechnicalMembership);
1569+
list_benchmark!(list, extra, pallet_mmr, Mmr);
1570+
list_benchmark!(list, extra, pallet_multisig, Multisig);
1571+
list_benchmark!(list, extra, pallet_offences, OffencesBench::<Runtime>);
1572+
list_benchmark!(list, extra, pallet_proxy, Proxy);
1573+
list_benchmark!(list, extra, pallet_scheduler, Scheduler);
1574+
list_benchmark!(list, extra, pallet_session, SessionBench::<Runtime>);
1575+
list_benchmark!(list, extra, pallet_staking, Staking);
1576+
list_benchmark!(list, extra, frame_system, SystemBench::<Runtime>);
1577+
list_benchmark!(list, extra, pallet_timestamp, Timestamp);
1578+
list_benchmark!(list, extra, pallet_tips, Tips);
1579+
list_benchmark!(list, extra, pallet_transaction_storage, TransactionStorage);
1580+
list_benchmark!(list, extra, pallet_treasury, Treasury);
1581+
list_benchmark!(list, extra, pallet_uniques, Uniques);
1582+
list_benchmark!(list, extra, pallet_utility, Utility);
1583+
list_benchmark!(list, extra, pallet_vesting, Vesting);
1584+
1585+
let storage_info = AllPalletsWithSystem::storage_info();
1586+
1587+
return (list, storage_info)
1588+
}
1589+
15371590
fn dispatch_benchmark(
15381591
config: frame_benchmarking::BenchmarkConfig
1539-
) -> Result<
1540-
(Vec<frame_benchmarking::BenchmarkBatch>, Vec<frame_support::traits::StorageInfo>),
1541-
sp_runtime::RuntimeString,
1542-
> {
1592+
) -> Result<Vec<frame_benchmarking::BenchmarkBatch>, sp_runtime::RuntimeString> {
15431593
use frame_benchmarking::{Benchmarking, BenchmarkBatch, add_benchmark, TrackedStorageKey};
1544-
use frame_support::traits::StorageInfoTrait;
15451594

15461595
// Trying to add benchmarks directly to the Session Pallet caused cyclic dependency
15471596
// issues. To get around that, we separated the Session benchmarks into its own crate,
@@ -1569,8 +1618,6 @@ impl_runtime_apis! {
15691618
hex_literal::hex!("26aa394eea5630e07c48ae0c9558cef7b99d880ec681799c0cf30e8886371da95ecffd7b6c0f78751baa9d281e0bfa3a6d6f646c70792f74727372790000000000000000000000000000000000000000").to_vec().into(),
15701619
];
15711620

1572-
let storage_info = AllPalletsWithSystem::storage_info();
1573-
15741621
let mut batches = Vec::<BenchmarkBatch>::new();
15751622
let params = (&config, &whitelist);
15761623

@@ -1607,7 +1654,7 @@ impl_runtime_apis! {
16071654
add_benchmark!(params, batches, pallet_vesting, Vesting);
16081655

16091656
if batches.is_empty() { return Err("Benchmark not found for this pallet.".into()) }
1610-
Ok((batches, storage_info))
1657+
Ok(batches)
16111658
}
16121659
}
16131660
}

frame/balances/src/weights.rs

+26-14
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@
1717

1818
//! Autogenerated weights for pallet_balances
1919
//!
20-
//! THIS FILE WAS AUTO-GENERATED USING THE SUBSTRATE BENCHMARK CLI VERSION 3.0.0
21-
//! DATE: 2021-06-19, STEPS: `[50, ]`, REPEAT: 20, LOW RANGE: `[]`, HIGH RANGE: `[]`
20+
//! THIS FILE WAS AUTO-GENERATED USING THE SUBSTRATE BENCHMARK CLI VERSION 4.0.0-dev
21+
//! DATE: 2021-07-30, STEPS: `50`, REPEAT: 20, LOW RANGE: `[]`, HIGH RANGE: `[]`
2222
//! EXECUTION: Some(Wasm), WASM-EXECUTION: Compiled, CHAIN: Some("dev"), DB CACHE: 128
2323
2424
// Executed Command:
@@ -56,67 +56,79 @@ pub trait WeightInfo {
5656
/// Weights for pallet_balances using the Substrate node and recommended hardware.
5757
pub struct SubstrateWeight<T>(PhantomData<T>);
5858
impl<T: frame_system::Config> WeightInfo for SubstrateWeight<T> {
59+
// Storage: System Account (r:1 w:1)
5960
fn transfer() -> Weight {
60-
(73_268_000 as Weight)
61+
(78_358_000 as Weight)
6162
.saturating_add(T::DbWeight::get().reads(1 as Weight))
6263
.saturating_add(T::DbWeight::get().writes(1 as Weight))
6364
}
65+
// Storage: System Account (r:1 w:1)
6466
fn transfer_keep_alive() -> Weight {
65-
(54_881_000 as Weight)
67+
(59_001_000 as Weight)
6668
.saturating_add(T::DbWeight::get().reads(1 as Weight))
6769
.saturating_add(T::DbWeight::get().writes(1 as Weight))
6870
}
71+
// Storage: System Account (r:1 w:1)
6972
fn set_balance_creating() -> Weight {
70-
(29_853_000 as Weight)
73+
(32_698_000 as Weight)
7174
.saturating_add(T::DbWeight::get().reads(1 as Weight))
7275
.saturating_add(T::DbWeight::get().writes(1 as Weight))
7376
}
77+
// Storage: System Account (r:1 w:1)
7478
fn set_balance_killing() -> Weight {
75-
(36_007_000 as Weight)
79+
(38_746_000 as Weight)
7680
.saturating_add(T::DbWeight::get().reads(1 as Weight))
7781
.saturating_add(T::DbWeight::get().writes(1 as Weight))
7882
}
83+
// Storage: System Account (r:2 w:2)
7984
fn force_transfer() -> Weight {
80-
(72_541_000 as Weight)
85+
(77_622_000 as Weight)
8186
.saturating_add(T::DbWeight::get().reads(2 as Weight))
8287
.saturating_add(T::DbWeight::get().writes(2 as Weight))
8388
}
89+
// Storage: System Account (r:1 w:1)
8490
fn transfer_all() -> Weight {
85-
(67_360_000 as Weight)
91+
(72_020_000 as Weight)
8692
.saturating_add(T::DbWeight::get().reads(1 as Weight))
8793
.saturating_add(T::DbWeight::get().writes(1 as Weight))
8894
}
8995
}
9096

9197
// For backwards compatibility and tests
9298
impl WeightInfo for () {
99+
// Storage: System Account (r:1 w:1)
93100
fn transfer() -> Weight {
94-
(73_268_000 as Weight)
101+
(78_358_000 as Weight)
95102
.saturating_add(RocksDbWeight::get().reads(1 as Weight))
96103
.saturating_add(RocksDbWeight::get().writes(1 as Weight))
97104
}
105+
// Storage: System Account (r:1 w:1)
98106
fn transfer_keep_alive() -> Weight {
99-
(54_881_000 as Weight)
107+
(59_001_000 as Weight)
100108
.saturating_add(RocksDbWeight::get().reads(1 as Weight))
101109
.saturating_add(RocksDbWeight::get().writes(1 as Weight))
102110
}
111+
// Storage: System Account (r:1 w:1)
103112
fn set_balance_creating() -> Weight {
104-
(29_853_000 as Weight)
113+
(32_698_000 as Weight)
105114
.saturating_add(RocksDbWeight::get().reads(1 as Weight))
106115
.saturating_add(RocksDbWeight::get().writes(1 as Weight))
107116
}
117+
// Storage: System Account (r:1 w:1)
108118
fn set_balance_killing() -> Weight {
109-
(36_007_000 as Weight)
119+
(38_746_000 as Weight)
110120
.saturating_add(RocksDbWeight::get().reads(1 as Weight))
111121
.saturating_add(RocksDbWeight::get().writes(1 as Weight))
112122
}
123+
// Storage: System Account (r:2 w:2)
113124
fn force_transfer() -> Weight {
114-
(72_541_000 as Weight)
125+
(77_622_000 as Weight)
115126
.saturating_add(RocksDbWeight::get().reads(2 as Weight))
116127
.saturating_add(RocksDbWeight::get().writes(2 as Weight))
117128
}
129+
// Storage: System Account (r:1 w:1)
118130
fn transfer_all() -> Weight {
119-
(67_360_000 as Weight)
131+
(72_020_000 as Weight)
120132
.saturating_add(RocksDbWeight::get().reads(1 as Weight))
121133
.saturating_add(RocksDbWeight::get().writes(1 as Weight))
122134
}

0 commit comments

Comments
 (0)