Browse Source

benchmark: working-group: add script for generating weights

conectado 4 years ago
parent
commit
db180673a4

+ 2 - 2
runtime-modules/proposals/codex/src/tests/mock.rs

@@ -264,10 +264,10 @@ impl working_group::WeightInfo for WorkingGroupWeightInfo {
     fn withdraw_application() -> Weight {
         0
     }
-    fn slash_stake() -> Weight {
+    fn slash_stake(_: u32) -> Weight {
         0
     }
-    fn terminate_role_worker() -> Weight {
+    fn terminate_role_worker(_: u32) -> Weight {
         0
     }
     fn terminate_role_lead() -> Weight {

+ 2 - 2
runtime-modules/service-discovery/src/mock.rs

@@ -182,10 +182,10 @@ impl working_group::WeightInfo for WorkingGroupWeightInfo {
     fn withdraw_application() -> Weight {
         0
     }
-    fn slash_stake() -> Weight {
+    fn slash_stake(_: u32) -> Weight {
         0
     }
-    fn terminate_role_worker() -> Weight {
+    fn terminate_role_worker(_: u32) -> Weight {
         0
     }
     fn terminate_role_lead() -> Weight {

+ 2 - 2
runtime-modules/storage/src/tests/mock.rs

@@ -198,10 +198,10 @@ impl working_group::WeightInfo for WorkingGroupWeightInfo {
     fn withdraw_application() -> Weight {
         0
     }
-    fn slash_stake() -> Weight {
+    fn slash_stake(_: u32) -> Weight {
         0
     }
-    fn terminate_role_worker() -> Weight {
+    fn terminate_role_worker(_: u32) -> Weight {
         0
     }
     fn terminate_role_lead() -> Weight {

+ 2 - 2
runtime-modules/working-group/src/benchmarking.rs

@@ -577,7 +577,7 @@ benchmarks_instance! {
     }
 
     fill_opening_worker {
-        let i in 2 .. T::MaxWorkerNumberLimit::get();
+        let i in 1 .. T::MaxWorkerNumberLimit::get() - 1;
         let (lead_id, lead_worker_id) = insert_a_worker::<T, I>(
             StakingRole::WithoutStakes,
             OpeningType::Leader,
@@ -587,7 +587,7 @@ benchmarks_instance! {
 
         let (opening_id, successful_application_ids, _) =
             add_opening_and_apply_with_multiple_ids::<T, I>(
-                &(1..i).collect(),
+                &(1..i+1).collect(),
                 &T::Origin::from(RawOrigin::Signed(lead_id.clone())),
                 &StakingRole::WithoutStakes,
                 &OpeningType::Regular

+ 12 - 6
runtime-modules/working-group/src/lib.rs

@@ -74,8 +74,8 @@ pub trait WeightInfo {
     fn update_role_account() -> Weight;
     fn cancel_opening() -> Weight;
     fn withdraw_application() -> Weight;
-    fn slash_stake() -> Weight; // Parameter not used so it's discarded
-    fn terminate_role_worker() -> Weight; // Parameter not used so it's discarded
+    fn slash_stake(i: u32) -> Weight;
+    fn terminate_role_worker(i: u32) -> Weight;
     fn terminate_role_lead() -> Weight; // Parameter not used so it's discarded
     fn increase_stake() -> Weight;
     fn decrease_stake() -> Weight;
@@ -566,12 +566,17 @@ decl_module! {
         /// # <weight>
         ///
         /// ## Weight
-        /// `O (1)`
+        /// `O (P)` where:
+        /// - `P` is the length of `penalty.slashing_text`
         /// - DB:
         ///    - O(1) doesn't depend on the state or parameters
         /// # </weight>
         #[weight = WeightInfoWorkingGroup::<T, I>::terminate_role_lead()
-                .max(WeightInfoWorkingGroup::<T, I>::terminate_role_worker())]
+                .max(WeightInfoWorkingGroup::<T, I>::terminate_role_worker(
+                        penalty.as_ref().map(|penalty| penalty.slashing_text.len().saturated_into())
+                            .unwrap_or_else(|| 0)
+                    )
+        )]
         pub fn terminate_role(
             origin,
             worker_id: WorkerId<T>,
@@ -617,11 +622,12 @@ decl_module! {
         /// # <weight>
         ///
         /// ## Weight
-        /// `O (1)`
+        /// `O (P)` where:
+        /// - `P` is the length of `penality.slashing_text`
         /// - DB:
         ///    - O(1) doesn't depend on the state or parameters
         /// # </weight>
-        #[weight = WeightInfoWorkingGroup::<T, I>::slash_stake()]
+        #[weight = WeightInfoWorkingGroup::<T, I>::slash_stake(penalty.slashing_text.len().saturated_into())]
         pub fn slash_stake(origin, worker_id: WorkerId<T>, penalty: Penalty<BalanceOf<T>>) {
             // Ensure lead is set or it is the council slashing the leader.
             checks::ensure_origin_for_worker_operation::<T,I>(origin, worker_id)?;

+ 2 - 2
runtime-modules/working-group/src/tests/mock.rs

@@ -155,10 +155,10 @@ impl crate::WeightInfo for () {
     fn withdraw_application() -> Weight {
         0
     }
-    fn slash_stake() -> Weight {
+    fn slash_stake(_: u32) -> Weight {
         0
     }
-    fn terminate_role_worker() -> Weight {
+    fn terminate_role_worker(_: u32) -> Weight {
         0
     }
     fn terminate_role_lead() -> Weight {

+ 35 - 35
runtime/src/weights/working_group.rs

@@ -9,7 +9,7 @@ pub struct WeightInfo;
 impl working_group::WeightInfo for WeightInfo {
     fn on_initialize_leaving(i: u32) -> Weight {
         (0 as Weight)
-            .saturating_add((613_524_000 as Weight).saturating_mul(i as Weight))
+            .saturating_add((661_028_000 as Weight).saturating_mul(i as Weight))
             .saturating_add(DbWeight::get().reads(4 as Weight))
             .saturating_add(DbWeight::get().reads((3 as Weight).saturating_mul(i as Weight)))
             .saturating_add(DbWeight::get().writes(3 as Weight))
@@ -17,125 +17,125 @@ impl working_group::WeightInfo for WeightInfo {
     }
     fn on_initialize_rewarding_with_missing_reward(i: u32) -> Weight {
         (0 as Weight)
-            .saturating_add((612_352_000 as Weight).saturating_mul(i as Weight))
+            .saturating_add((470_374_000 as Weight).saturating_mul(i as Weight))
             .saturating_add(DbWeight::get().reads(2 as Weight))
             .saturating_add(DbWeight::get().reads((2 as Weight).saturating_mul(i as Weight)))
             .saturating_add(DbWeight::get().writes(1 as Weight))
             .saturating_add(DbWeight::get().writes((1 as Weight).saturating_mul(i as Weight)))
     }
     fn on_initialize_rewarding_with_missing_reward_cant_pay(i: u32) -> Weight {
-        (0 as Weight)
-            .saturating_add((378_633_000 as Weight).saturating_mul(i as Weight))
+        (90_637_000 as Weight)
+            .saturating_add((326_660_000 as Weight).saturating_mul(i as Weight))
             .saturating_add(DbWeight::get().reads(2 as Weight))
             .saturating_add(DbWeight::get().reads((1 as Weight).saturating_mul(i as Weight)))
             .saturating_add(DbWeight::get().writes((1 as Weight).saturating_mul(i as Weight)))
     }
     fn on_initialize_rewarding_without_missing_reward(i: u32) -> Weight {
-        (168_498_000 as Weight)
-            .saturating_add((339_619_000 as Weight).saturating_mul(i as Weight))
+        (168_436_000 as Weight)
+            .saturating_add((297_407_000 as Weight).saturating_mul(i as Weight))
             .saturating_add(DbWeight::get().reads(2 as Weight))
             .saturating_add(DbWeight::get().reads((2 as Weight).saturating_mul(i as Weight)))
             .saturating_add(DbWeight::get().writes(2 as Weight))
     }
     fn apply_on_opening(i: u32) -> Weight {
-        (603_703_000 as Weight)
-            .saturating_add((1_000 as Weight).saturating_mul(i as Weight))
+        (549_364_000 as Weight)
+            .saturating_add((2_000 as Weight).saturating_mul(i as Weight))
             .saturating_add(DbWeight::get().reads(5 as Weight))
             .saturating_add(DbWeight::get().writes(4 as Weight))
     }
     fn fill_opening_lead() -> Weight {
-        (521_141_000 as Weight)
+        (507_605_000 as Weight)
             .saturating_add(DbWeight::get().reads(5 as Weight))
             .saturating_add(DbWeight::get().writes(6 as Weight))
     }
     fn fill_opening_worker(i: u32) -> Weight {
-        (0 as Weight)
-            .saturating_add((339_256_000 as Weight).saturating_mul(i as Weight))
-            .saturating_add(DbWeight::get().reads(4 as Weight))
+        (215_972_000 as Weight)
+            .saturating_add((295_997_000 as Weight).saturating_mul(i as Weight))
+            .saturating_add(DbWeight::get().reads(5 as Weight))
             .saturating_add(DbWeight::get().reads((1 as Weight).saturating_mul(i as Weight)))
-            .saturating_add(DbWeight::get().writes(1 as Weight))
+            .saturating_add(DbWeight::get().writes(3 as Weight))
             .saturating_add(DbWeight::get().writes((2 as Weight).saturating_mul(i as Weight)))
     }
     fn update_role_account() -> Weight {
-        (408_130_000 as Weight)
+        (366_128_000 as Weight)
             .saturating_add(DbWeight::get().reads(2 as Weight))
             .saturating_add(DbWeight::get().writes(1 as Weight))
     }
     fn cancel_opening() -> Weight {
-        (280_562_000 as Weight)
+        (267_071_000 as Weight)
             .saturating_add(DbWeight::get().reads(3 as Weight))
             .saturating_add(DbWeight::get().writes(1 as Weight))
     }
     fn withdraw_application() -> Weight {
-        (407_575_000 as Weight)
+        (372_243_000 as Weight)
             .saturating_add(DbWeight::get().reads(3 as Weight))
             .saturating_add(DbWeight::get().writes(3 as Weight))
     }
-    // WARNING! Some components were not used: ["i"]
-    fn slash_stake() -> Weight {
-        (911_451_000 as Weight)
+    fn slash_stake(i: u32) -> Weight {
+        (751_074_000 as Weight)
+            .saturating_add((1_000 as Weight).saturating_mul(i as Weight))
             .saturating_add(DbWeight::get().reads(5 as Weight))
             .saturating_add(DbWeight::get().writes(2 as Weight))
     }
-    // WARNING! Some components were not used: ["i"]
-    fn terminate_role_worker() -> Weight {
-        (1_373_099_000 as Weight)
+    fn terminate_role_worker(i: u32) -> Weight {
+        (1_208_516_000 as Weight)
+            .saturating_add((1_000 as Weight).saturating_mul(i as Weight))
             .saturating_add(DbWeight::get().reads(7 as Weight))
             .saturating_add(DbWeight::get().writes(5 as Weight))
     }
     // WARNING! Some components were not used: ["i"]
     fn terminate_role_lead() -> Weight {
-        (1_271_775_000 as Weight)
+        (1_158_631_000 as Weight)
             .saturating_add(DbWeight::get().reads(6 as Weight))
             .saturating_add(DbWeight::get().writes(6 as Weight))
     }
     fn increase_stake() -> Weight {
-        (725_110_000 as Weight)
+        (712_005_000 as Weight)
             .saturating_add(DbWeight::get().reads(3 as Weight))
             .saturating_add(DbWeight::get().writes(2 as Weight))
     }
     fn decrease_stake() -> Weight {
-        (835_788_000 as Weight)
+        (800_137_000 as Weight)
             .saturating_add(DbWeight::get().reads(5 as Weight))
             .saturating_add(DbWeight::get().writes(2 as Weight))
     }
     fn spend_from_budget() -> Weight {
-        (305_871_000 as Weight)
+        (285_147_000 as Weight)
             .saturating_add(DbWeight::get().reads(4 as Weight))
             .saturating_add(DbWeight::get().writes(1 as Weight))
     }
     fn update_reward_amount() -> Weight {
-        (419_462_000 as Weight)
+        (390_432_000 as Weight)
             .saturating_add(DbWeight::get().reads(3 as Weight))
             .saturating_add(DbWeight::get().writes(1 as Weight))
     }
     fn set_status_text(i: u32) -> Weight {
-        (253_519_000 as Weight)
-            .saturating_add((66_000 as Weight).saturating_mul(i as Weight))
+        (222_153_000 as Weight)
+            .saturating_add((60_000 as Weight).saturating_mul(i as Weight))
             .saturating_add(DbWeight::get().reads(2 as Weight))
             .saturating_add(DbWeight::get().writes(1 as Weight))
     }
     fn update_reward_account() -> Weight {
-        (302_517_000 as Weight)
+        (282_438_000 as Weight)
             .saturating_add(DbWeight::get().reads(1 as Weight))
             .saturating_add(DbWeight::get().writes(1 as Weight))
     }
     fn set_budget() -> Weight {
-        (77_498_000 as Weight).saturating_add(DbWeight::get().writes(1 as Weight))
+        (74_429_000 as Weight).saturating_add(DbWeight::get().writes(1 as Weight))
     }
     fn add_opening(i: u32) -> Weight {
-        (278_869_000 as Weight)
-            .saturating_add((1_000 as Weight).saturating_mul(i as Weight))
+        (263_062_000 as Weight)
+            .saturating_add((2_000 as Weight).saturating_mul(i as Weight))
             .saturating_add(DbWeight::get().reads(3 as Weight))
             .saturating_add(DbWeight::get().writes(2 as Weight))
     }
     fn leave_role_immediatly() -> Weight {
-        (511_210_000 as Weight)
+        (483_595_000 as Weight)
             .saturating_add(DbWeight::get().reads(5 as Weight))
             .saturating_add(DbWeight::get().writes(4 as Weight))
     }
     fn leave_role_later() -> Weight {
-        (322_685_000 as Weight)
+        (315_015_000 as Weight)
             .saturating_add(DbWeight::get().reads(2 as Weight))
             .saturating_add(DbWeight::get().writes(1 as Weight))
     }

+ 5 - 0
scripts/generate-weights.sh

@@ -16,3 +16,8 @@ echo "Benchmarking pallet_constitution..."
 ./target/release/joystream-node benchmark --pallet=pallet_constitution --extrinsic=* --chain=dev --steps=50 --repeat=20 --execution=wasm --output=. > /dev/null
 mv pallet_constitution.rs runtime/src/weights/
 echo "pallet_constitution benchmarked"
+
+echo "Benchmarking working_group..."
+./target/release/joystream-node benchmark --pallet=working_group --extrinsic=* --chain=dev --steps=50 --repeat=20 --execution=wasm --output=. > /dev/null
+mv working_group.rs runtime/src/weights/
+echo "working_group benchmarked"