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

Add benchmarking for parachain runtime paras pallet #3888

Merged
22 commits merged into from
Sep 22, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
00065e5
Crate basic barebones benchmarking infrastructure for paras
KiChjang Sep 17, 2021
0d967d5
Fill in benchmarking contents
KiChjang Sep 18, 2021
7122391
Merge branch 'master' of https://github.com/paritytech/polkadot into …
Sep 18, 2021
f5ceca5
cargo run --quiet --release --features=runtime-benchmarks -- benchmar…
Sep 18, 2021
0e4cac8
cargo run --quiet --release --features=runtime-benchmarks -- benchmar…
Sep 18, 2021
264bb07
Use autogenerated WeightInfos for kusama and westend
KiChjang Sep 18, 2021
e2fe358
cargo fmt
KiChjang Sep 18, 2021
20388c8
Use saturating_sub
KiChjang Sep 18, 2021
d92cb3f
Add missing import
KiChjang Sep 18, 2021
ee36011
Merge branch 'master' into kckyeung/parachains-paras-benchmarking
KiChjang Sep 18, 2021
5a368b2
Try and hit the worst possible time complexity as much as possible
KiChjang Sep 19, 2021
0b47140
cargo fmt
KiChjang Sep 19, 2021
0bd9cd2
Merge branch 'master' of https://github.com/paritytech/polkadot into …
Sep 19, 2021
f9ceaf3
cargo run --quiet --release --features=runtime-benchmarks -- benchmar…
Sep 19, 2021
69b4b5f
cargo run --quiet --release --features=runtime-benchmarks -- benchmar…
Sep 19, 2021
7c79304
Add a MAX_HEAD_DATA_SIZE constant
KiChjang Sep 20, 2021
496bf51
Prefill vectors with sample data for worst case complexity
KiChjang Sep 21, 2021
74c46f4
Merge branch 'master' of https://github.com/paritytech/polkadot into …
Sep 21, 2021
10b97f9
cargo run --quiet --release --features=runtime-benchmarks -- benchmar…
Sep 21, 2021
fcd3c43
Merge branch 'master' of https://github.com/paritytech/polkadot into …
Sep 21, 2021
0a0b1cc
cargo run --quiet --release --features=runtime-benchmarks -- benchmar…
Sep 21, 2021
b91f0e5
Improve comment on SAMPLE_SIZE constant
KiChjang Sep 21, 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
10 changes: 5 additions & 5 deletions runtime/parachains/src/paras.rs
Original file line number Diff line number Diff line change
Expand Up @@ -505,7 +505,7 @@ pub mod pallet {
#[pallet::call]
impl<T: Config> Pallet<T> {
/// Set the storage for the parachain validation code immediately.
#[pallet::weight(T::WeightInfo::force_set_current_code(new_code.0.len() as u32))]
#[pallet::weight(<T as Config>::WeightInfo::force_set_current_code(new_code.0.len() as u32))]
pub fn force_set_current_code(
origin: OriginFor<T>,
para: ParaId,
Expand All @@ -524,7 +524,7 @@ pub mod pallet {
}

/// Set the storage for the current parachain head data immediately.
#[pallet::weight(T::WeightInfo::force_set_current_head())]
#[pallet::weight(<T as Config>::WeightInfo::force_set_current_head())]
pub fn force_set_current_head(
origin: OriginFor<T>,
para: ParaId,
Expand All @@ -537,7 +537,7 @@ pub mod pallet {
}

/// Schedule an upgrade as if it was scheduled in the given relay parent block.
#[pallet::weight(T::WeightInfo::force_schedule_code_upgrade(new_code.0.len() as u32))]
#[pallet::weight(<T as Config>::WeightInfo::force_schedule_code_upgrade(new_code.0.len() as u32))]
pub fn force_schedule_code_upgrade(
origin: OriginFor<T>,
para: ParaId,
Expand All @@ -552,7 +552,7 @@ pub mod pallet {
}

/// Note a new block head for para within the context of the current block.
#[pallet::weight(T::WeightInfo::force_note_new_head())]
#[pallet::weight(<T as Config>::WeightInfo::force_note_new_head())]
pub fn force_note_new_head(
origin: OriginFor<T>,
para: ParaId,
Expand All @@ -568,7 +568,7 @@ pub mod pallet {
/// Put a parachain directly into the next session's action queue.
/// We can't queue it any sooner than this without going into the
/// initializer...
#[pallet::weight(T::WeightInfo::force_queue_action())]
#[pallet::weight(<T as Config>::WeightInfo::force_queue_action())]
pub fn force_queue_action(origin: OriginFor<T>, para: ParaId) -> DispatchResult {
ensure_root(origin)?;
let next_session = shared::Pallet::<T>::session_index().saturating_add(One::one());
Expand Down
23 changes: 19 additions & 4 deletions runtime/parachains/src/paras/benchmarking.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,10 @@
// along with Polkadot. If not, see <http://www.gnu.org/licenses/>.

use super::*;
use crate::configuration::HostConfiguration;
use crate::configuration::{self, HostConfiguration};
use frame_benchmarking::{benchmarks, impl_benchmark_test_suite};
use frame_system::RawOrigin;
use primitives::v1::{HeadData, Id as ParaId, ValidationCode};
use primitives::v1::{HeadData, Id as ParaId, ValidationCode, MAX_CODE_SIZE};
use sp_runtime::traits::{One, Saturating};

fn assert_last_event<T: Config>(generic_event: <T as Config>::Event) {
Expand All @@ -29,17 +29,31 @@ fn assert_last_event<T: Config>(generic_event: <T as Config>::Event) {
assert_eq!(event, &system_event);
}

fn generate_disordered_pruning<T: Config>() {
let mut needs_pruning = Vec::new();

for i in 0 .. 1000 {
let id = ParaId::from(i);
let block_number = T::BlockNumber::from(1000u32);
needs_pruning.push((id, block_number));
}

<Pallet<T> as Store>::PastCodePruning::put(needs_pruning);
}

benchmarks! {
force_set_current_code {
let c in 1024 .. 2048;
let c in 1 .. MAX_CODE_SIZE;
let new_code = ValidationCode(vec![0; c as usize]);
let para_id = ParaId::from(c as u32);
generate_disordered_pruning::<T>();
}: _(RawOrigin::Root, para_id, new_code)
verify {
assert_last_event::<T>(Event::CurrentCodeUpdated(para_id).into());
}
force_set_current_head {
let new_head = HeadData(vec![0]);
let max_head_data_size = configuration::Pallet::<T>::config().max_head_data_size as usize;
shawntabrizi marked this conversation as resolved.
Show resolved Hide resolved
let new_head = HeadData(vec![0; max_head_data_size]);
let para_id = ParaId::from(1000);
}: _(RawOrigin::Root, para_id, new_head)
verify {
Expand All @@ -61,6 +75,7 @@ benchmarks! {
// the worst possible code path
let expired = frame_system::Pallet::<T>::block_number().saturating_sub(One::one());
let config = HostConfiguration::<T::BlockNumber>::default();
generate_disordered_pruning::<T>();
Pallet::<T>::schedule_code_upgrade(para_id, ValidationCode(vec![0]), expired, &config);
}: _(RawOrigin::Root, para_id, new_head)
verify {
Expand Down
29 changes: 18 additions & 11 deletions runtime/parachains/src/paras/weights.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
//! Autogenerated weights for `runtime_parachains::paras`
//!
//! THIS FILE WAS AUTO-GENERATED USING THE SUBSTRATE BENCHMARK CLI VERSION 4.0.0-dev
//! DATE: 2021-09-18, STEPS: `50`, REPEAT: 20, LOW RANGE: `[]`, HIGH RANGE: `[]`
//! DATE: 2021-09-19, STEPS: `50`, REPEAT: 20, LOW RANGE: `[]`, HIGH RANGE: `[]`
//! EXECUTION: Some(Wasm), WASM-EXECUTION: Compiled, CHAIN: Some("westend-dev"), DB CACHE: 128

// Executed Command:
Expand Down Expand Up @@ -42,15 +42,15 @@ impl<T: frame_system::Config> super::WeightInfo for WeightInfo<T> {
// Storage: Paras PastCodeHash (r:0 w:1)
// Storage: Paras CodeByHash (r:0 w:1)
fn force_set_current_code(c: u32, ) -> Weight {
(44_794_000 as Weight)
(21_013_000 as Weight)
// Standard Error: 0
.saturating_add((2_000 as Weight).saturating_mul(c as Weight))
.saturating_add((3_000 as Weight).saturating_mul(c as Weight))
.saturating_add(T::DbWeight::get().reads(4 as Weight))
.saturating_add(T::DbWeight::get().writes(6 as Weight))
}
// Storage: Paras Heads (r:0 w:1)
fn force_set_current_head() -> Weight {
(18_999_000 as Weight)
(74_866_000 as Weight)
.saturating_add(T::DbWeight::get().writes(1 as Weight))
}
// Storage: Configuration ActiveConfig (r:1 w:0)
Expand All @@ -63,23 +63,30 @@ impl<T: frame_system::Config> super::WeightInfo for WeightInfo<T> {
// Storage: Paras FutureCodeHash (r:0 w:1)
// Storage: Paras UpgradeRestrictionSignal (r:0 w:1)
fn force_schedule_code_upgrade(c: u32, ) -> Weight {
(50_520_000 as Weight)
(49_334_000 as Weight)
// Standard Error: 0
.saturating_add((2_000 as Weight).saturating_mul(c as Weight))
.saturating_add((3_000 as Weight).saturating_mul(c as Weight))
.saturating_add(T::DbWeight::get().reads(6 as Weight))
.saturating_add(T::DbWeight::get().writes(8 as Weight))
}
// Storage: Paras FutureCodeUpgrades (r:1 w:0)
// Storage: Paras FutureCodeUpgrades (r:1 w:1)
// Storage: Paras FutureCodeHash (r:1 w:1)
// Storage: Paras CurrentCodeHash (r:1 w:1)
// Storage: System Digest (r:1 w:1)
// Storage: Paras PastCodeMeta (r:1 w:1)
// Storage: Paras PastCodePruning (r:1 w:1)
// Storage: Paras Heads (r:0 w:1)
// Storage: Paras PastCodeHash (r:0 w:1)
// Storage: Paras UpgradeGoAheadSignal (r:0 w:1)
fn force_note_new_head() -> Weight {
(26_383_000 as Weight)
.saturating_add(T::DbWeight::get().reads(1 as Weight))
.saturating_add(T::DbWeight::get().writes(1 as Weight))
(82_810_000 as Weight)
.saturating_add(T::DbWeight::get().reads(6 as Weight))
.saturating_add(T::DbWeight::get().writes(9 as Weight))
}
// Storage: ParasShared CurrentSessionIndex (r:1 w:0)
// Storage: Paras ActionsQueue (r:1 w:1)
fn force_queue_action() -> Weight {
(24_305_000 as Weight)
(24_440_000 as Weight)
.saturating_add(T::DbWeight::get().reads(2 as Weight))
.saturating_add(T::DbWeight::get().writes(1 as Weight))
}
Expand Down