Skip to content
This repository was archived by the owner on Nov 15, 2023. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
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
Prev Previous commit
Next Next commit
integrate weightinfo
  • Loading branch information
shawntabrizi committed Sep 18, 2020
commit d03b600bc09600f7b39eddadb673bef3ba9bfecf
2 changes: 2 additions & 0 deletions frame/scheduler/src/benchmarking.rs
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,8 @@ benchmarks! {
);
}

// TODO: Make this more complex and flexible so it can be used in automation.
#[extra]
on_initialize {
let s in 0 .. T::MaxScheduledPerBlock::get();
let when = BLOCK_NUMBER.into();
Expand Down
7 changes: 0 additions & 7 deletions frame/scheduler/src/default_weights.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,11 +47,4 @@ impl crate::WeightInfo for () {
.saturating_add(DbWeight::get().reads(2 as Weight))
.saturating_add(DbWeight::get().writes(2 as Weight))
}
fn on_initialize(s: u32, ) -> Weight {
(21_651_000 as Weight)
.saturating_add((33_001_000 as Weight).saturating_mul(s as Weight))
.saturating_add(DbWeight::get().reads(2 as Weight))
.saturating_add(DbWeight::get().writes(2 as Weight))
.saturating_add(DbWeight::get().writes((1 as Weight).saturating_mul(s as Weight)))
}
}
23 changes: 10 additions & 13 deletions frame/scheduler/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,6 @@ pub trait WeightInfo {
fn cancel(s: u32, ) -> Weight;
fn schedule_named(s: u32, ) -> Weight;
fn cancel_named(s: u32, ) -> Weight;
fn on_initialize(s: u32, ) -> Weight;
}

/// Our pallet's configuration trait. All our types and constants go in here. If the
Expand Down Expand Up @@ -210,7 +209,7 @@ decl_module! {
/// - Write: Agenda
/// - Will use base weight of 25 which should be good for up to 30 scheduled calls
/// # </weight>
#[weight = 25_000_000 + T::DbWeight::get().reads_writes(1, 1)]
#[weight = T::WeightInfo::schedule(T::MaxScheduledPerBlock::get())]
fn schedule(origin,
when: T::BlockNumber,
maybe_periodic: Option<schedule::Period<T::BlockNumber>>,
Expand All @@ -232,7 +231,7 @@ decl_module! {
/// - Write: Agenda, Lookup
/// - Will use base weight of 100 which should be good for up to 30 scheduled calls
/// # </weight>
#[weight = 100_000_000 + T::DbWeight::get().reads_writes(1, 2)]
#[weight = T::WeightInfo::cancel(T::MaxScheduledPerBlock::get())]
fn cancel(origin, when: T::BlockNumber, index: u32) {
T::ScheduleOrigin::ensure_origin(origin.clone())?;
let origin = <T as Trait>::Origin::from(origin);
Expand All @@ -249,7 +248,7 @@ decl_module! {
/// - Write: Agenda, Lookup
/// - Will use base weight of 35 which should be good for more than 30 scheduled calls
/// # </weight>
#[weight = 35_000_000 + T::DbWeight::get().reads_writes(2, 2)]
#[weight = T::WeightInfo::schedule_named(T::MaxScheduledPerBlock::get())]
fn schedule_named(origin,
id: Vec<u8>,
when: T::BlockNumber,
Expand All @@ -274,7 +273,7 @@ decl_module! {
/// - Write: Agenda, Lookup
/// - Will use base weight of 100 which should be good for up to 30 scheduled calls
/// # </weight>
#[weight = 100_000_000 + T::DbWeight::get().reads_writes(2, 2)]
#[weight = T::WeightInfo::cancel_named(T::MaxScheduledPerBlock::get())]
fn cancel_named(origin, id: Vec<u8>) {
T::ScheduleOrigin::ensure_origin(origin.clone())?;
let origin = <T as Trait>::Origin::from(origin);
Expand All @@ -286,7 +285,7 @@ decl_module! {
/// # <weight>
/// Same as [`schedule`].
/// # </weight>
#[weight = 25_000_000 + T::DbWeight::get().reads_writes(1, 1)]
#[weight = T::WeightInfo::schedule(T::MaxScheduledPerBlock::get())]
fn schedule_after(origin,
after: T::BlockNumber,
maybe_periodic: Option<schedule::Period<T::BlockNumber>>,
Expand All @@ -305,7 +304,7 @@ decl_module! {
/// # <weight>
/// Same as [`schedule_named`].
/// # </weight>
#[weight = 35_000_000 + T::DbWeight::get().reads_writes(2, 2)]
#[weight = T::WeightInfo::schedule_named(T::MaxScheduledPerBlock::get())]
fn schedule_named_after(origin,
id: Vec<u8>,
after: T::BlockNumber,
Expand Down Expand Up @@ -344,15 +343,13 @@ decl_module! {
);
}
queued.sort_by_key(|(_, s)| s.priority);
let base_weight: Weight = T::DbWeight::get().reads_writes(1, 2) // Agenda + Agenda(next)
.saturating_add(10_000_000); // Base Weight
let base_weight: Weight = T::DbWeight::get().reads_writes(1, 2); // Agenda + Agenda(next)
let mut total_weight: Weight = 0;
queued.into_iter()
.enumerate()
.scan(base_weight, |cumulative_weight, (order, (index, s))| {
*cumulative_weight = cumulative_weight
.saturating_add(s.call.get_dispatch_info().weight)
.saturating_add(25_000_000); // Base multiplier
.saturating_add(s.call.get_dispatch_info().weight);

if s.maybe_id.is_some() {
// Remove/Modify Lookup
Expand Down Expand Up @@ -999,8 +996,8 @@ mod tests {
#[test]
fn on_initialize_weight_is_correct() {
new_test_ext().execute_with(|| {
let base_weight: Weight = <Test as frame_system::Trait>::DbWeight::get().reads_writes(1, 2) + 10_000_000;
let base_multiplier = 25_000_000;
let base_weight: Weight = <Test as frame_system::Trait>::DbWeight::get().reads_writes(1, 2);
let base_multiplier = 0;
let named_multiplier = <Test as frame_system::Trait>::DbWeight::get().writes(1);
let periodic_multiplier = <Test as frame_system::Trait>::DbWeight::get().reads_writes(1, 1);

Expand Down