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

Refactor Benchmarks for Less Wasm Memory Usage #9373

Merged
77 commits merged into from
Aug 1, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
77 commits
Select commit Hold shift + click to select a range
c13b500
extract repeat out of benchmark
shawntabrizi Jul 19, 2021
c309539
remove r
shawntabrizi Jul 19, 2021
e909b9d
unused
shawntabrizi Jul 19, 2021
6e70861
cargo run --quiet --release --features=runtime-benchmarks --manifest-…
Jul 19, 2021
30e9e5f
cargo run --quiet --release --features=runtime-benchmarks --manifest-…
Jul 19, 2021
66c1dbb
cargo run --quiet --release --features=runtime-benchmarks --manifest-…
Jul 19, 2021
cd01587
use linked map to keep order
shawntabrizi Jul 21, 2021
8c42f39
Merge branch 'master' of https://github.com/paritytech/substrate into…
Jul 21, 2021
d0184a0
cargo run --quiet --release --features=runtime-benchmarks --manifest-…
Jul 21, 2021
31810d9
Delete pallet_balances.rs
shawntabrizi Jul 21, 2021
1ab0066
Delete out
shawntabrizi Jul 21, 2021
257fbbb
cargo run --quiet --release --features=runtime-benchmarks --manifest-…
Jul 21, 2021
ca5cdc5
steps and repeat to tuple (current_*, total_*)
shawntabrizi Jul 22, 2021
f42d16f
idea for list command
shawntabrizi Jul 22, 2021
8a0ed37
Merge branch 'master' into shawntabrizi-refactor-benchmarks
shawntabrizi Jul 29, 2021
81a7e77
fmt
shawntabrizi Jul 29, 2021
9467179
use benchmark list in cli
shawntabrizi Jul 30, 2021
e760e3e
handle steps in cli
shawntabrizi Jul 30, 2021
630ab7a
move log update to cli
shawntabrizi Jul 30, 2021
d4b3f9d
fmt
shawntabrizi Jul 30, 2021
39bd8c0
remove old todo
shawntabrizi Jul 30, 2021
fb8fc17
line width
shawntabrizi Jul 30, 2021
0f713c7
Merge branch 'master' of https://github.com/paritytech/substrate into…
Jul 30, 2021
5627eba
cargo run --quiet --release --features=runtime-benchmarks --manifest-…
Jul 30, 2021
ced0514
benchmark metadata function
shawntabrizi Jul 30, 2021
1945af5
don't need this warm up
shawntabrizi Jul 30, 2021
b243b02
cargo run --quiet --release --features=runtime-benchmarks --manifest-…
Jul 30, 2021
14a4342
fix warnings
shawntabrizi Jul 30, 2021
ee3b2f7
fix node-template
shawntabrizi Jul 30, 2021
0ae6038
fix
shawntabrizi Jul 30, 2021
f2ae7a1
fmt
shawntabrizi Jul 31, 2021
b7fa4aa
line width
shawntabrizi Jul 31, 2021
f5a839b
cargo run --quiet --release --features=runtime-benchmarks --manifest-…
Jul 31, 2021
e3ad6dd
improve docs
shawntabrizi Jul 31, 2021
98b3280
improve cli
shawntabrizi Jul 31, 2021
cc6e48b
fix format
shawntabrizi Jul 31, 2021
8051bf1
fix bug?
shawntabrizi Aug 1, 2021
d62a13e
Revert "fix bug?"
shawntabrizi Aug 1, 2021
0e20a92
skip frame-metadata
shawntabrizi Aug 1, 2021
a6aa550
extract repeat out of benchmark
shawntabrizi Jul 19, 2021
5cbc0fe
remove r
shawntabrizi Jul 19, 2021
a7ed886
cargo run --quiet --release --features=runtime-benchmarks --manifest-…
Jul 19, 2021
4079b32
cargo run --quiet --release --features=runtime-benchmarks --manifest-…
Jul 19, 2021
fbd8e48
cargo run --quiet --release --features=runtime-benchmarks --manifest-…
Jul 19, 2021
05ee330
use linked map to keep order
shawntabrizi Jul 21, 2021
8cf07b4
cargo run --quiet --release --features=runtime-benchmarks --manifest-…
Jul 21, 2021
4518215
Delete pallet_balances.rs
shawntabrizi Jul 21, 2021
8de8043
Delete out
shawntabrizi Jul 21, 2021
8c27b0b
cargo run --quiet --release --features=runtime-benchmarks --manifest-…
Jul 21, 2021
69b5649
steps and repeat to tuple (current_*, total_*)
shawntabrizi Jul 22, 2021
bf949d0
idea for list command
shawntabrizi Jul 22, 2021
19553a7
fmt
shawntabrizi Jul 29, 2021
bea0029
use benchmark list in cli
shawntabrizi Jul 30, 2021
80d5ab3
handle steps in cli
shawntabrizi Jul 30, 2021
6f06056
move log update to cli
shawntabrizi Jul 30, 2021
7f88e7f
remove old todo
shawntabrizi Jul 30, 2021
cc4479a
line width
shawntabrizi Jul 30, 2021
83e5a49
cargo run --quiet --release --features=runtime-benchmarks --manifest-…
Jul 30, 2021
33a8243
benchmark metadata function
shawntabrizi Jul 30, 2021
a366ed2
don't need this warm up
shawntabrizi Jul 30, 2021
60cdd06
cargo run --quiet --release --features=runtime-benchmarks --manifest-…
Jul 30, 2021
a2c2dbd
fix warnings
shawntabrizi Jul 30, 2021
c8f7ce1
fix node-template
shawntabrizi Jul 30, 2021
0a3043b
fix
shawntabrizi Jul 30, 2021
04df7e8
fmt
shawntabrizi Jul 31, 2021
2a0d85e
line width
shawntabrizi Jul 31, 2021
20ccbc7
cargo run --quiet --release --features=runtime-benchmarks --manifest-…
Jul 31, 2021
4f1a560
improve docs
shawntabrizi Jul 31, 2021
e743100
improve cli
shawntabrizi Jul 31, 2021
f1fdbac
fix format
shawntabrizi Jul 31, 2021
2ed43f3
fix bug?
shawntabrizi Aug 1, 2021
17f33f8
Revert "fix bug?"
shawntabrizi Aug 1, 2021
70eeb9f
skip frame-metadata
shawntabrizi Aug 1, 2021
7420ed0
Merge branch 'shawntabrizi-refactor-benchmarks' of https://github.com…
shawntabrizi Aug 1, 2021
048b452
Update .gitlab-ci.yml
shawntabrizi Aug 1, 2021
0c0e112
fix import
shawntabrizi Aug 1, 2021
fec5ee2
Update .gitlab-ci.yml
shawntabrizi Aug 1, 2021
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions .gitlab-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -273,7 +273,7 @@ node-bench-regression-guard:
CI_IMAGE: "paritytech/node-bench-regression-guard:latest"
before_script: [""]
script:
- 'node-bench-regression-guard --reference artifacts/benches/master-*
- 'node-bench-regression-guard --reference artifacts/benches/master-*
--compare-with artifacts/benches/$CI_COMMIT_REF_NAME-$CI_COMMIT_SHORT_SHA'

cargo-check-subkey:
Expand Down Expand Up @@ -343,6 +343,7 @@ unleash-check:
- mkdir -p target/unleash
- export CARGO_TARGET_DIR=target/unleash
- cargo unleash check ${CARGO_UNLEASH_PKG_DEF}
allow_failure: true

test-frame-examples-compile-to-wasm:
# into one job
Expand Down Expand Up @@ -578,7 +579,7 @@ build-rust-doc:
- buildah push --format=v2s2 "$IMAGE_NAME:latest"
after_script:
- buildah logout "$IMAGE_NAME"
# pass artifacts to the trigger-simnet job
# pass artifacts to the trigger-simnet job
- echo "IMAGE_NAME=${IMAGE_NAME}" | tee -a ./artifacts/$PRODUCT/build.env
- IMAGE_TAG="$(cat ./artifacts/$PRODUCT/VERSION)"
- echo "IMAGE_TAG=${IMAGE_TAG}" | tee -a ./artifacts/$PRODUCT/build.env
Expand Down Expand Up @@ -713,7 +714,7 @@ trigger-simnet:
- if: $CI_COMMIT_REF_NAME == "master"
needs:
- job: publish-docker-substrate
# `build.env` brings here `$IMAGE_NAME` and `$IMAGE_TAG` (`$VERSION` here,
# `build.env` brings here `$IMAGE_NAME` and `$IMAGE_TAG` (`$VERSION` here,
# i.e. `2643-0.8.29-5f689e0a-6b24dc54`).
variables:
TRGR_PROJECT: ${CI_PROJECT_NAME}
Expand Down
2 changes: 2 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

30 changes: 22 additions & 8 deletions bin/node-template/runtime/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -446,14 +446,30 @@ impl_runtime_apis! {

#[cfg(feature = "runtime-benchmarks")]
impl frame_benchmarking::Benchmark<Block> for Runtime {
fn benchmark_metadata(extra: bool) -> (
Vec<frame_benchmarking::BenchmarkList>,
Vec<frame_support::traits::StorageInfo>,
) {
use frame_benchmarking::{list_benchmark, Benchmarking, BenchmarkList};
use frame_support::traits::StorageInfoTrait;
use frame_system_benchmarking::Pallet as SystemBench;

let mut list = Vec::<BenchmarkList>::new();

list_benchmark!(list, extra, frame_system, SystemBench::<Runtime>);
list_benchmark!(list, extra, pallet_balances, Balances);
list_benchmark!(list, extra, pallet_timestamp, Timestamp);
list_benchmark!(list, extra, pallet_template, TemplateModule);

let storage_info = AllPalletsWithSystem::storage_info();

return (list, storage_info)
}

fn dispatch_benchmark(
config: frame_benchmarking::BenchmarkConfig
) -> Result<
(Vec<frame_benchmarking::BenchmarkBatch>, Vec<StorageInfo>),
sp_runtime::RuntimeString,
> {
) -> Result<Vec<frame_benchmarking::BenchmarkBatch>, sp_runtime::RuntimeString> {
use frame_benchmarking::{Benchmarking, BenchmarkBatch, add_benchmark, TrackedStorageKey};
use frame_support::traits::StorageInfoTrait;

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

let storage_info = AllPalletsWithSystem::storage_info();

let mut batches = Vec::<BenchmarkBatch>::new();
let params = (&config, &whitelist);

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

if batches.is_empty() { return Err("Benchmark not found for this pallet.".into()) }
Ok((batches, storage_info))
Ok(batches)
}
}
}
63 changes: 55 additions & 8 deletions bin/node/runtime/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1534,14 +1534,63 @@ impl_runtime_apis! {

#[cfg(feature = "runtime-benchmarks")]
impl frame_benchmarking::Benchmark<Block> for Runtime {
fn benchmark_metadata(extra: bool) -> (
Vec<frame_benchmarking::BenchmarkList>,
Vec<frame_support::traits::StorageInfo>,
) {
use frame_benchmarking::{list_benchmark, Benchmarking, BenchmarkList};
use frame_support::traits::StorageInfoTrait;

// Trying to add benchmarks directly to the Session Pallet caused cyclic dependency
// issues. To get around that, we separated the Session benchmarks into its own crate,
// which is why we need these two lines below.
use pallet_session_benchmarking::Pallet as SessionBench;
use pallet_offences_benchmarking::Pallet as OffencesBench;
use frame_system_benchmarking::Pallet as SystemBench;

let mut list = Vec::<BenchmarkList>::new();

list_benchmark!(list, extra, pallet_assets, Assets);
list_benchmark!(list, extra, pallet_babe, Babe);
list_benchmark!(list, extra, pallet_balances, Balances);
list_benchmark!(list, extra, pallet_bounties, Bounties);
list_benchmark!(list, extra, pallet_collective, Council);
list_benchmark!(list, extra, pallet_contracts, Contracts);
list_benchmark!(list, extra, pallet_democracy, Democracy);
list_benchmark!(list, extra, pallet_election_provider_multi_phase, ElectionProviderMultiPhase);
list_benchmark!(list, extra, pallet_elections_phragmen, Elections);
list_benchmark!(list, extra, pallet_gilt, Gilt);
list_benchmark!(list, extra, pallet_grandpa, Grandpa);
list_benchmark!(list, extra, pallet_identity, Identity);
list_benchmark!(list, extra, pallet_im_online, ImOnline);
list_benchmark!(list, extra, pallet_indices, Indices);
list_benchmark!(list, extra, pallet_lottery, Lottery);
list_benchmark!(list, extra, pallet_membership, TechnicalMembership);
list_benchmark!(list, extra, pallet_mmr, Mmr);
list_benchmark!(list, extra, pallet_multisig, Multisig);
list_benchmark!(list, extra, pallet_offences, OffencesBench::<Runtime>);
list_benchmark!(list, extra, pallet_proxy, Proxy);
list_benchmark!(list, extra, pallet_scheduler, Scheduler);
list_benchmark!(list, extra, pallet_session, SessionBench::<Runtime>);
list_benchmark!(list, extra, pallet_staking, Staking);
list_benchmark!(list, extra, frame_system, SystemBench::<Runtime>);
list_benchmark!(list, extra, pallet_timestamp, Timestamp);
list_benchmark!(list, extra, pallet_tips, Tips);
list_benchmark!(list, extra, pallet_transaction_storage, TransactionStorage);
list_benchmark!(list, extra, pallet_treasury, Treasury);
list_benchmark!(list, extra, pallet_uniques, Uniques);
list_benchmark!(list, extra, pallet_utility, Utility);
list_benchmark!(list, extra, pallet_vesting, Vesting);

let storage_info = AllPalletsWithSystem::storage_info();

return (list, storage_info)
}

fn dispatch_benchmark(
config: frame_benchmarking::BenchmarkConfig
) -> Result<
(Vec<frame_benchmarking::BenchmarkBatch>, Vec<frame_support::traits::StorageInfo>),
sp_runtime::RuntimeString,
> {
) -> Result<Vec<frame_benchmarking::BenchmarkBatch>, sp_runtime::RuntimeString> {
use frame_benchmarking::{Benchmarking, BenchmarkBatch, add_benchmark, TrackedStorageKey};
use frame_support::traits::StorageInfoTrait;

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

let storage_info = AllPalletsWithSystem::storage_info();

let mut batches = Vec::<BenchmarkBatch>::new();
let params = (&config, &whitelist);

Expand Down Expand Up @@ -1607,7 +1654,7 @@ impl_runtime_apis! {
add_benchmark!(params, batches, pallet_vesting, Vesting);

if batches.is_empty() { return Err("Benchmark not found for this pallet.".into()) }
Ok((batches, storage_info))
Ok(batches)
}
}
}
Expand Down
40 changes: 26 additions & 14 deletions frame/balances/src/weights.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@

//! Autogenerated weights for pallet_balances
//!
//! THIS FILE WAS AUTO-GENERATED USING THE SUBSTRATE BENCHMARK CLI VERSION 3.0.0
//! DATE: 2021-06-19, STEPS: `[50, ]`, REPEAT: 20, LOW RANGE: `[]`, HIGH RANGE: `[]`
//! THIS FILE WAS AUTO-GENERATED USING THE SUBSTRATE BENCHMARK CLI VERSION 4.0.0-dev
//! DATE: 2021-07-30, STEPS: `50`, REPEAT: 20, LOW RANGE: `[]`, HIGH RANGE: `[]`
//! EXECUTION: Some(Wasm), WASM-EXECUTION: Compiled, CHAIN: Some("dev"), DB CACHE: 128

// Executed Command:
Expand Down Expand Up @@ -56,67 +56,79 @@ pub trait WeightInfo {
/// Weights for pallet_balances using the Substrate node and recommended hardware.
pub struct SubstrateWeight<T>(PhantomData<T>);
impl<T: frame_system::Config> WeightInfo for SubstrateWeight<T> {
// Storage: System Account (r:1 w:1)
fn transfer() -> Weight {
(73_268_000 as Weight)
(78_358_000 as Weight)
.saturating_add(T::DbWeight::get().reads(1 as Weight))
.saturating_add(T::DbWeight::get().writes(1 as Weight))
}
// Storage: System Account (r:1 w:1)
fn transfer_keep_alive() -> Weight {
(54_881_000 as Weight)
(59_001_000 as Weight)
.saturating_add(T::DbWeight::get().reads(1 as Weight))
.saturating_add(T::DbWeight::get().writes(1 as Weight))
}
// Storage: System Account (r:1 w:1)
fn set_balance_creating() -> Weight {
(29_853_000 as Weight)
(32_698_000 as Weight)
.saturating_add(T::DbWeight::get().reads(1 as Weight))
.saturating_add(T::DbWeight::get().writes(1 as Weight))
}
// Storage: System Account (r:1 w:1)
fn set_balance_killing() -> Weight {
(36_007_000 as Weight)
(38_746_000 as Weight)
.saturating_add(T::DbWeight::get().reads(1 as Weight))
.saturating_add(T::DbWeight::get().writes(1 as Weight))
}
// Storage: System Account (r:2 w:2)
fn force_transfer() -> Weight {
(72_541_000 as Weight)
(77_622_000 as Weight)
.saturating_add(T::DbWeight::get().reads(2 as Weight))
.saturating_add(T::DbWeight::get().writes(2 as Weight))
}
// Storage: System Account (r:1 w:1)
fn transfer_all() -> Weight {
(67_360_000 as Weight)
(72_020_000 as Weight)
.saturating_add(T::DbWeight::get().reads(1 as Weight))
.saturating_add(T::DbWeight::get().writes(1 as Weight))
}
}

// For backwards compatibility and tests
impl WeightInfo for () {
// Storage: System Account (r:1 w:1)
fn transfer() -> Weight {
(73_268_000 as Weight)
(78_358_000 as Weight)
.saturating_add(RocksDbWeight::get().reads(1 as Weight))
.saturating_add(RocksDbWeight::get().writes(1 as Weight))
}
// Storage: System Account (r:1 w:1)
fn transfer_keep_alive() -> Weight {
(54_881_000 as Weight)
(59_001_000 as Weight)
.saturating_add(RocksDbWeight::get().reads(1 as Weight))
.saturating_add(RocksDbWeight::get().writes(1 as Weight))
}
// Storage: System Account (r:1 w:1)
fn set_balance_creating() -> Weight {
(29_853_000 as Weight)
(32_698_000 as Weight)
.saturating_add(RocksDbWeight::get().reads(1 as Weight))
.saturating_add(RocksDbWeight::get().writes(1 as Weight))
}
// Storage: System Account (r:1 w:1)
fn set_balance_killing() -> Weight {
(36_007_000 as Weight)
(38_746_000 as Weight)
.saturating_add(RocksDbWeight::get().reads(1 as Weight))
.saturating_add(RocksDbWeight::get().writes(1 as Weight))
}
// Storage: System Account (r:2 w:2)
fn force_transfer() -> Weight {
(72_541_000 as Weight)
(77_622_000 as Weight)
.saturating_add(RocksDbWeight::get().reads(2 as Weight))
.saturating_add(RocksDbWeight::get().writes(2 as Weight))
}
// Storage: System Account (r:1 w:1)
fn transfer_all() -> Weight {
(67_360_000 as Weight)
(72_020_000 as Weight)
.saturating_add(RocksDbWeight::get().reads(1 as Weight))
.saturating_add(RocksDbWeight::get().writes(1 as Weight))
}
Expand Down
Loading