Browse Source

Forum_v2: add weight funtions

iorveth 4 years ago
parent
commit
28f4b38196

+ 2 - 2
runtime-modules/forum/src/benchmarking.rs

@@ -287,7 +287,7 @@ pub fn generate_categories_tree<T: Trait>(
 
     let text = vec![0u8].repeat(MAX_BYTES as usize);
 
-    for n in 0..T::MaxCategoryDepth::get() {
+    for n in 0..=T::MaxCategoryDepth::get() {
         if n > 1 {
             parent_category_id = Some((n as u64).into());
         }
@@ -810,7 +810,7 @@ benchmarks! {
 
         let mut post = Module::<T>::post_by_id(thread_id, post_id);
 
-        let new_text = vec![0u8].repeat(MAX_BYTES as usize);
+        let new_text = vec![0u8].repeat(i as usize);
 
     }: _ (RawOrigin::Signed(caller_id), (forum_user_id as u64).into(), category_id, thread_id, post_id, new_text.clone())
     verify {

+ 31 - 0
runtime-modules/forum/src/lib.rs

@@ -21,6 +21,29 @@ mod tests;
 
 mod benchmarking;
 
+type WeightInfoForum<T> = <T as Trait>::WeightInfo;
+
+/// pallet_forum WeightInfo.
+/// Note: This was auto generated through the benchmark CLI using the `--weight-trait` flag
+pub trait WeightInfo {
+    fn create_category(j: u32) -> Weight;
+    fn update_category_membership_of_moderator(i: u32) -> Weight;
+    fn update_category_archival_status() -> Weight;
+    fn delete_category() -> Weight;
+    fn create_thread(j: u32, i: u32) -> Weight;
+    fn edit_thread_title(j: u32) -> Weight;
+    fn update_thread_archival_status() -> Weight;
+    fn delete_thread() -> Weight;
+    fn move_thread_to_category() -> Weight;
+    fn vote_on_poll(i: u32) -> Weight;
+    fn moderate_thread(i: u32) -> Weight;
+    fn add_post(i: u32) -> Weight;
+    fn react_post() -> Weight;
+    fn edit_post_text(i: u32) -> Weight;
+    fn moderate_post(i: u32) -> Weight;
+    fn set_stickied_threads(i: u32) -> Weight;
+}
+
 pub trait Trait: frame_system::Trait + pallet_timestamp::Trait + Sized {
     type Event: From<Event<Self>> + Into<<Self as frame_system::Trait>::Event>;
     type ForumUserId: Parameter
@@ -92,6 +115,9 @@ pub trait Trait: frame_system::Trait + pallet_timestamp::Trait + Sized {
     type MaxCategoryDepth: Get<u64>;
     type MapLimits: StorageLimits;
 
+    /// Weight information for extrinsics in this pallet.
+    type WeightInfo: WeightInfo;
+
     fn is_lead(account_id: &<Self as frame_system::Trait>::AccountId) -> bool;
     fn is_forum_member(
         account_id: &<Self as frame_system::Trait>::AccountId,
@@ -446,6 +472,11 @@ decl_module! {
         fn deposit_event() = default;
 
         /// Enable a moderator can moderate a category and its sub categories.
+        /// # <weight>
+        /// - Complexity: `O(C)` where C is the length of the constitution text.
+        /// - Db reads: 0
+        /// - Db writes: 1 (constant value)
+        /// # </weight>
         #[weight = 10_000_000] // TODO: adjust weight
         fn update_category_membership_of_moderator(origin, moderator_id: T::ModeratorId, category_id: T::CategoryId, new_value: bool) -> DispatchResult {
             // Ensure data migration is done

+ 1 - 0
runtime/src/lib.rs

@@ -666,6 +666,7 @@ impl forum::Trait for Runtime {
     type MaxCategoryDepth = MaxCategoryDepth;
 
     type MapLimits = MapLimits;
+    type WeightInfo = weights::forum::WeightInfo;
 
     fn is_lead(_account_id: &AccountId) -> bool {
         // get current lead id

+ 101 - 0
runtime/src/weights/forum.rs

@@ -0,0 +1,101 @@
+//! THIS FILE WAS AUTO-GENERATED USING THE SUBSTRATE BENCHMARK CLI VERSION 2.0.0
+
+#![allow(unused_parens)]
+#![allow(unused_imports)]
+
+use frame_support::weights::{constants::RocksDbWeight as DbWeight, Weight};
+
+pub struct WeightInfo;
+impl forum::WeightInfo for WeightInfo {
+    fn create_category(j: u32) -> Weight {
+        (1_191_268_000 as Weight)
+            .saturating_add((137_000 as Weight).saturating_mul(j as Weight))
+            .saturating_add(DbWeight::get().reads(9 as Weight))
+            .saturating_add(DbWeight::get().writes(4 as Weight))
+    }
+    fn update_category_membership_of_moderator(i: u32) -> Weight {
+        (468_391_000 as Weight)
+            .saturating_add((30_963_000 as Weight).saturating_mul(i as Weight))
+            .saturating_add(DbWeight::get().reads(4 as Weight))
+            .saturating_add(DbWeight::get().reads((1 as Weight).saturating_mul(i as Weight)))
+            .saturating_add(DbWeight::get().writes(2 as Weight))
+    }
+    fn update_category_archival_status() -> Weight {
+        (732_069_000 as Weight)
+            .saturating_add(DbWeight::get().reads(7 as Weight))
+            .saturating_add(DbWeight::get().writes(1 as Weight))
+    }
+    fn delete_category() -> Weight {
+        (779_355_000 as Weight)
+            .saturating_add(DbWeight::get().reads(8 as Weight))
+            .saturating_add(DbWeight::get().writes(3 as Weight))
+    }
+    fn create_thread(j: u32, i: u32) -> Weight {
+        (926_921_000 as Weight)
+            .saturating_add((162_000 as Weight).saturating_mul(j as Weight))
+            .saturating_add((8_925_000 as Weight).saturating_mul(i as Weight))
+            .saturating_add(DbWeight::get().reads(11 as Weight))
+            .saturating_add(DbWeight::get().writes(5 as Weight))
+    }
+    fn edit_thread_title(j: u32) -> Weight {
+        (837_426_000 as Weight)
+            .saturating_add((83_000 as Weight).saturating_mul(j as Weight))
+            .saturating_add(DbWeight::get().reads(7 as Weight))
+            .saturating_add(DbWeight::get().writes(1 as Weight))
+    }
+    fn update_thread_archival_status() -> Weight {
+        (1_241_769_000 as Weight)
+            .saturating_add(DbWeight::get().reads(8 as Weight))
+            .saturating_add(DbWeight::get().writes(1 as Weight))
+    }
+    fn delete_thread() -> Weight {
+        (1_253_622_000 as Weight)
+            .saturating_add(DbWeight::get().reads(8 as Weight))
+            .saturating_add(DbWeight::get().writes(22 as Weight))
+    }
+    fn move_thread_to_category() -> Weight {
+        (1_356_642_000 as Weight)
+            .saturating_add(DbWeight::get().reads(8 as Weight))
+            .saturating_add(DbWeight::get().writes(4 as Weight))
+    }
+    fn vote_on_poll(i: u32) -> Weight {
+        (914_355_000 as Weight)
+            .saturating_add((33_864_000 as Weight).saturating_mul(i as Weight))
+            .saturating_add(DbWeight::get().reads(8 as Weight))
+            .saturating_add(DbWeight::get().writes(1 as Weight))
+    }
+    fn moderate_thread(i: u32) -> Weight {
+        (1_238_371_000 as Weight)
+            .saturating_add((234_000 as Weight).saturating_mul(i as Weight))
+            .saturating_add(DbWeight::get().reads(8 as Weight))
+            .saturating_add(DbWeight::get().writes(22 as Weight))
+    }
+    fn add_post(i: u32) -> Weight {
+        (922_212_000 as Weight)
+            .saturating_add((78_000 as Weight).saturating_mul(i as Weight))
+            .saturating_add(DbWeight::get().reads(9 as Weight))
+            .saturating_add(DbWeight::get().writes(3 as Weight))
+    }
+    fn react_post() -> Weight {
+        (1_039_552_000 as Weight).saturating_add(DbWeight::get().reads(8 as Weight))
+    }
+    fn edit_post_text(i: u32) -> Weight {
+        (2_424_803_000 as Weight)
+            .saturating_add((1_000 as Weight).saturating_mul(i as Weight))
+            .saturating_add(DbWeight::get().reads(8 as Weight))
+            .saturating_add(DbWeight::get().writes(1 as Weight))
+    }
+    fn moderate_post(i: u32) -> Weight {
+        (1_979_246_000 as Weight)
+            .saturating_add((239_000 as Weight).saturating_mul(i as Weight))
+            .saturating_add(DbWeight::get().reads(9 as Weight))
+            .saturating_add(DbWeight::get().writes(2 as Weight))
+    }
+    fn set_stickied_threads(i: u32) -> Weight {
+        (575_507_000 as Weight)
+            .saturating_add((381_753_000 as Weight).saturating_mul(i as Weight))
+            .saturating_add(DbWeight::get().reads(7 as Weight))
+            .saturating_add(DbWeight::get().reads((1 as Weight).saturating_mul(i as Weight)))
+            .saturating_add(DbWeight::get().writes(1 as Weight))
+    }
+}

+ 1 - 0
runtime/src/weights/mod.rs

@@ -24,6 +24,7 @@ pub mod pallet_timestamp;
 pub mod pallet_utility;
 
 // Joystream pallets
+pub mod forum;
 pub mod pallet_constitution;
 pub mod proposals_discussion;
 pub mod proposals_engine;

+ 10 - 8
scripts/generate-weights.sh

@@ -28,10 +28,10 @@ benchmark() {
 }
 
 # FRAME benchmarks
-benchmark frame_system
-benchmark pallet_utility
-benchmark pallet_session
-benchmark pallet_timestamp
+# benchmark frame_system
+# benchmark pallet_utility
+# benchmark pallet_session
+# benchmark pallet_timestamp
 
 # This benchmark takes too long with 50 steps and 20 repeats in a normal laptop.
 # Will have it commented out until we test it in the reference machine. If there
@@ -40,7 +40,9 @@ benchmark pallet_timestamp
 # benchmark pallet_im_online
 
 # Joystrem benchmarks
-benchmark proposals_discussion
-benchmark proposals_engine
-benchmark pallet_constitution
-benchmark working_group
+# benchmark proposals_discussion
+# benchmark proposals_engine
+# benchmark pallet_constitution
+# benchmark working_group
+benchmark forum
+