From f2f19bf45d08b909bb3c1147b81144ae8399ea27 Mon Sep 17 00:00:00 2001 From: Trubnikov Sergey Date: Wed, 20 Jul 2022 11:04:44 +0000 Subject: [PATCH] minor: add bechmarks for RFT collection & token properties --- --- a/pallets/refungible/src/benchmarking.rs +++ b/pallets/refungible/src/benchmarking.rs @@ -18,9 +18,9 @@ use crate::{Pallet, Config, RefungibleHandle}; use sp_std::prelude::*; -use pallet_common::benchmarking::{create_collection_raw, create_data}; +use pallet_common::benchmarking::{create_collection_raw, property_key, property_value, create_data}; use frame_benchmarking::{benchmarks, account}; -use up_data_structs::{CollectionMode, MAX_ITEMS_PER_BATCH, CUSTOM_DATA_LIMIT, budget::Unlimited}; +use up_data_structs::{CollectionMode, MAX_ITEMS_PER_BATCH, MAX_PROPERTIES_PER_ITEM, CUSTOM_DATA_LIMIT, budget::Unlimited}; use pallet_common::bench_init; use core::convert::TryInto; use core::iter::IntoIterator; @@ -205,6 +205,68 @@ >::set_allowance(&collection, &sender, &burner, item, 200)?; }: {>::burn_from(&collection, &burner, &sender, item, 200, &Unlimited)?} + set_token_property_permissions { + let b in 0..MAX_PROPERTIES_PER_ITEM; + bench_init!{ + owner: sub; collection: collection(owner); + owner: cross_from_sub; + }; + let perms = (0..b).map(|k| PropertyKeyPermission { + key: property_key(k as usize), + permission: PropertyPermission { + mutable: false, + collection_admin: false, + token_owner: false, + }, + }).collect::>(); + }: {>::set_token_property_permissions(&collection, &owner, perms)?} + + set_token_properties { + let b in 0..MAX_PROPERTIES_PER_ITEM; + bench_init!{ + owner: sub; collection: collection(owner); + owner: cross_from_sub; + }; + let perms = (0..b).map(|k| PropertyKeyPermission { + key: property_key(k as usize), + permission: PropertyPermission { + mutable: false, + collection_admin: true, + token_owner: true, + }, + }).collect::>(); + >::set_token_property_permissions(&collection, &owner, perms)?; + let props = (0..b).map(|k| Property { + key: property_key(k as usize), + value: property_value(), + }).collect::>(); + let item = create_max_item(&collection, &owner, [(owner.clone(), 200)])?; + }: {>::set_token_properties(&collection, &owner, item, props.into_iter(), false, &Unlimited)?} + + delete_token_properties { + let b in 0..MAX_PROPERTIES_PER_ITEM; + bench_init!{ + owner: sub; collection: collection(owner); + owner: cross_from_sub; + }; + let perms = (0..b).map(|k| PropertyKeyPermission { + key: property_key(k as usize), + permission: PropertyPermission { + mutable: true, + collection_admin: true, + token_owner: true, + }, + }).collect::>(); + >::set_token_property_permissions(&collection, &owner, perms)?; + let props = (0..b).map(|k| Property { + key: property_key(k as usize), + value: property_value(), + }).collect::>(); + let item = create_max_item(&collection, &owner, [(owner.clone(), 200)])?; + >::set_token_properties(&collection, &owner, item, props.into_iter(), false, &Unlimited)?; + let to_delete = (0..b).map(|k| property_key(k as usize)).collect::>(); + }: {>::delete_token_properties(&collection, &owner, item, to_delete.into_iter(), &Unlimited)?} + repartition_item { bench_init!{ owner: sub; collection: collection(owner); --- a/pallets/refungible/src/common.rs +++ b/pallets/refungible/src/common.rs @@ -22,7 +22,7 @@ CollectionId, TokenId, CreateItemExData, CreateRefungibleExData, budget::Budget, Property, PropertyKey, PropertyValue, PropertyKeyPermission, CreateItemData, }; -use pallet_common::{CommonCollectionOperations, CommonWeightInfo, RefungibleExtensions, with_weight}; +use pallet_common::{CommonCollectionOperations, CommonWeightInfo, RefungibleExtensions, with_weight, weights::WeightInfo as _}; use pallet_structure::Error as StructureError; use sp_runtime::{DispatchError}; use sp_std::{vec::Vec, vec}; @@ -67,29 +67,24 @@ max_weight_of!(burn_item_partial(), burn_item_fully()) } - fn set_collection_properties(_amount: u32) -> Weight { - // Error - 0 + fn set_collection_properties(amount: u32) -> Weight { + >::set_collection_properties(amount) } - fn delete_collection_properties(_amount: u32) -> Weight { - // Error - 0 + fn delete_collection_properties(amount: u32) -> Weight { + >::delete_collection_properties(amount) } - fn set_token_properties(_amount: u32) -> Weight { - // Error - 0 + fn set_token_properties(amount: u32) -> Weight { + >::set_token_properties(amount) } - fn delete_token_properties(_amount: u32) -> Weight { - // Error - 0 + fn delete_token_properties(amount: u32) -> Weight { + >::delete_token_properties(amount) } - fn set_token_property_permissions(_amount: u32) -> Weight { - // Error - 0 + fn set_token_property_permissions(amount: u32) -> Weight { + >::set_token_property_permissions(amount) } fn transfer() -> Weight { --- a/pallets/refungible/src/weights.rs +++ b/pallets/refungible/src/weights.rs @@ -3,7 +3,7 @@ //! Autogenerated weights for pallet_refungible //! //! THIS FILE WAS AUTO-GENERATED USING THE SUBSTRATE BENCHMARK CLI VERSION 4.0.0-dev -//! DATE: 2022-06-27, STEPS: `50`, REPEAT: 80, LOW RANGE: `[]`, HIGH RANGE: `[]` +//! DATE: 2022-07-20, STEPS: `50`, REPEAT: 80, LOW RANGE: `[]`, HIGH RANGE: `[]` //! EXECUTION: None, WASM-EXECUTION: Compiled, CHAIN: None, DB CACHE: 1024 // Executed Command: @@ -49,6 +49,9 @@ fn transfer_from_removing() -> Weight; fn transfer_from_creating_removing() -> Weight; fn burn_from() -> Weight; + fn set_token_property_permissions(b: u32, ) -> Weight; + fn set_token_properties(b: u32, ) -> Weight; + fn delete_token_properties(b: u32, ) -> Weight; fn repartition_item() -> Weight; } @@ -62,7 +65,7 @@ // Storage: Refungible TokenData (r:0 w:1) // Storage: Refungible Owned (r:0 w:1) fn create_item() -> Weight { - (17_553_000 as Weight) + (21_310_000 as Weight) .saturating_add(T::DbWeight::get().reads(2 as Weight)) .saturating_add(T::DbWeight::get().writes(6 as Weight)) } @@ -73,9 +76,9 @@ // Storage: Refungible TokenData (r:0 w:4) // Storage: Refungible Owned (r:0 w:4) fn create_multiple_items(b: u32, ) -> Weight { - (10_654_000 as Weight) - // Standard Error: 1_000 - .saturating_add((5_114_000 as Weight).saturating_mul(b as Weight)) + (9_552_000 as Weight) + // Standard Error: 2_000 + .saturating_add((7_056_000 as Weight).saturating_mul(b as Weight)) .saturating_add(T::DbWeight::get().reads(2 as Weight)) .saturating_add(T::DbWeight::get().writes(2 as Weight)) .saturating_add(T::DbWeight::get().writes((4 as Weight).saturating_mul(b as Weight))) @@ -87,9 +90,9 @@ // Storage: Refungible TokenData (r:0 w:4) // Storage: Refungible Owned (r:0 w:4) fn create_multiple_items_ex_multiple_items(b: u32, ) -> Weight { - (3_587_000 as Weight) + (4_857_000 as Weight) // Standard Error: 2_000 - .saturating_add((7_931_000 as Weight).saturating_mul(b as Weight)) + .saturating_add((9_838_000 as Weight).saturating_mul(b as Weight)) .saturating_add(T::DbWeight::get().reads(1 as Weight)) .saturating_add(T::DbWeight::get().reads((1 as Weight).saturating_mul(b as Weight))) .saturating_add(T::DbWeight::get().writes(1 as Weight)) @@ -102,9 +105,9 @@ // Storage: Refungible Balance (r:0 w:4) // Storage: Refungible Owned (r:0 w:4) fn create_multiple_items_ex_multiple_owners(b: u32, ) -> Weight { - (1_980_000 as Weight) + (11_335_000 as Weight) // Standard Error: 2_000 - .saturating_add((6_305_000 as Weight).saturating_mul(b as Weight)) + .saturating_add((6_784_000 as Weight).saturating_mul(b as Weight)) .saturating_add(T::DbWeight::get().reads(1 as Weight)) .saturating_add(T::DbWeight::get().reads((1 as Weight).saturating_mul(b as Weight))) .saturating_add(T::DbWeight::get().writes(3 as Weight)) @@ -115,7 +118,7 @@ // Storage: Refungible AccountBalance (r:1 w:1) // Storage: Refungible Owned (r:0 w:1) fn burn_item_partial() -> Weight { - (21_010_000 as Weight) + (21_239_000 as Weight) .saturating_add(T::DbWeight::get().reads(3 as Weight)) .saturating_add(T::DbWeight::get().writes(4 as Weight)) } @@ -125,14 +128,15 @@ // Storage: Refungible TokensBurnt (r:1 w:1) // Storage: Refungible TokenData (r:0 w:1) // Storage: Refungible Owned (r:0 w:1) + // Storage: Refungible TokenProperties (r:0 w:1) fn burn_item_fully() -> Weight { - (28_413_000 as Weight) + (29_426_000 as Weight) .saturating_add(T::DbWeight::get().reads(4 as Weight)) - .saturating_add(T::DbWeight::get().writes(6 as Weight)) + .saturating_add(T::DbWeight::get().writes(7 as Weight)) } // Storage: Refungible Balance (r:2 w:2) fn transfer_normal() -> Weight { - (17_513_000 as Weight) + (17_743_000 as Weight) .saturating_add(T::DbWeight::get().reads(2 as Weight)) .saturating_add(T::DbWeight::get().writes(2 as Weight)) } @@ -140,7 +144,7 @@ // Storage: Refungible AccountBalance (r:1 w:1) // Storage: Refungible Owned (r:0 w:1) fn transfer_creating() -> Weight { - (20_469_000 as Weight) + (20_699_000 as Weight) .saturating_add(T::DbWeight::get().reads(3 as Weight)) .saturating_add(T::DbWeight::get().writes(4 as Weight)) } @@ -148,7 +152,7 @@ // Storage: Refungible AccountBalance (r:1 w:1) // Storage: Refungible Owned (r:0 w:1) fn transfer_removing() -> Weight { - (22_472_000 as Weight) + (22_833_000 as Weight) .saturating_add(T::DbWeight::get().reads(3 as Weight)) .saturating_add(T::DbWeight::get().writes(4 as Weight)) } @@ -156,21 +160,21 @@ // Storage: Refungible AccountBalance (r:2 w:2) // Storage: Refungible Owned (r:0 w:2) fn transfer_creating_removing() -> Weight { - (24_866_000 as Weight) + (24_936_000 as Weight) .saturating_add(T::DbWeight::get().reads(4 as Weight)) .saturating_add(T::DbWeight::get().writes(6 as Weight)) } // Storage: Refungible Balance (r:1 w:0) // Storage: Refungible Allowance (r:0 w:1) fn approve() -> Weight { - (13_475_000 as Weight) + (13_446_000 as Weight) .saturating_add(T::DbWeight::get().reads(1 as Weight)) .saturating_add(T::DbWeight::get().writes(1 as Weight)) } // Storage: Refungible Allowance (r:1 w:1) // Storage: Refungible Balance (r:2 w:2) fn transfer_from_normal() -> Weight { - (24_707_000 as Weight) + (24_777_000 as Weight) .saturating_add(T::DbWeight::get().reads(3 as Weight)) .saturating_add(T::DbWeight::get().writes(3 as Weight)) } @@ -179,7 +183,7 @@ // Storage: Refungible AccountBalance (r:1 w:1) // Storage: Refungible Owned (r:0 w:1) fn transfer_from_creating() -> Weight { - (27_812_000 as Weight) + (28_483_000 as Weight) .saturating_add(T::DbWeight::get().reads(4 as Weight)) .saturating_add(T::DbWeight::get().writes(5 as Weight)) } @@ -188,7 +192,7 @@ // Storage: Refungible AccountBalance (r:1 w:1) // Storage: Refungible Owned (r:0 w:1) fn transfer_from_removing() -> Weight { - (29_966_000 as Weight) + (29_896_000 as Weight) .saturating_add(T::DbWeight::get().reads(4 as Weight)) .saturating_add(T::DbWeight::get().writes(5 as Weight)) } @@ -197,7 +201,7 @@ // Storage: Refungible AccountBalance (r:2 w:2) // Storage: Refungible Owned (r:0 w:2) fn transfer_from_creating_removing() -> Weight { - (31_660_000 as Weight) + (32_070_000 as Weight) .saturating_add(T::DbWeight::get().reads(5 as Weight)) .saturating_add(T::DbWeight::get().writes(7 as Weight)) } @@ -208,15 +212,42 @@ // Storage: Refungible TokensBurnt (r:1 w:1) // Storage: Refungible TokenData (r:0 w:1) // Storage: Refungible Owned (r:0 w:1) + // Storage: Refungible TokenProperties (r:0 w:1) fn burn_from() -> Weight { - (36_248_000 as Weight) + (36_789_000 as Weight) .saturating_add(T::DbWeight::get().reads(5 as Weight)) - .saturating_add(T::DbWeight::get().writes(7 as Weight)) + .saturating_add(T::DbWeight::get().writes(8 as Weight)) + } + // Storage: Common CollectionPropertyPermissions (r:1 w:1) + fn set_token_property_permissions(b: u32, ) -> Weight { + (0 as Weight) + // Standard Error: 62_000 + .saturating_add((15_803_000 as Weight).saturating_mul(b as Weight)) + .saturating_add(T::DbWeight::get().reads(1 as Weight)) + .saturating_add(T::DbWeight::get().writes(1 as Weight)) + } + // Storage: Common CollectionPropertyPermissions (r:1 w:0) + // Storage: Refungible TokenProperties (r:1 w:1) + fn set_token_properties(b: u32, ) -> Weight { + (0 as Weight) + // Standard Error: 1_668_000 + .saturating_add((302_308_000 as Weight).saturating_mul(b as Weight)) + .saturating_add(T::DbWeight::get().reads(2 as Weight)) + .saturating_add(T::DbWeight::get().writes(1 as Weight)) + } + // Storage: Common CollectionPropertyPermissions (r:1 w:0) + // Storage: Refungible TokenProperties (r:1 w:1) + fn delete_token_properties(b: u32, ) -> Weight { + (0 as Weight) + // Standard Error: 1_619_000 + .saturating_add((294_574_000 as Weight).saturating_mul(b as Weight)) + .saturating_add(T::DbWeight::get().reads(2 as Weight)) + .saturating_add(T::DbWeight::get().writes(1 as Weight)) } // Storage: Refungible TotalSupply (r:1 w:1) // Storage: Refungible Balance (r:1 w:1) fn repartition_item() -> Weight { - (8_226_000 as Weight) + (8_325_000 as Weight) .saturating_add(T::DbWeight::get().reads(2 as Weight)) .saturating_add(T::DbWeight::get().writes(2 as Weight)) } @@ -231,7 +262,7 @@ // Storage: Refungible TokenData (r:0 w:1) // Storage: Refungible Owned (r:0 w:1) fn create_item() -> Weight { - (17_553_000 as Weight) + (21_310_000 as Weight) .saturating_add(RocksDbWeight::get().reads(2 as Weight)) .saturating_add(RocksDbWeight::get().writes(6 as Weight)) } @@ -242,9 +273,9 @@ // Storage: Refungible TokenData (r:0 w:4) // Storage: Refungible Owned (r:0 w:4) fn create_multiple_items(b: u32, ) -> Weight { - (10_654_000 as Weight) - // Standard Error: 1_000 - .saturating_add((5_114_000 as Weight).saturating_mul(b as Weight)) + (9_552_000 as Weight) + // Standard Error: 2_000 + .saturating_add((7_056_000 as Weight).saturating_mul(b as Weight)) .saturating_add(RocksDbWeight::get().reads(2 as Weight)) .saturating_add(RocksDbWeight::get().writes(2 as Weight)) .saturating_add(RocksDbWeight::get().writes((4 as Weight).saturating_mul(b as Weight))) @@ -256,9 +287,9 @@ // Storage: Refungible TokenData (r:0 w:4) // Storage: Refungible Owned (r:0 w:4) fn create_multiple_items_ex_multiple_items(b: u32, ) -> Weight { - (3_587_000 as Weight) + (4_857_000 as Weight) // Standard Error: 2_000 - .saturating_add((7_931_000 as Weight).saturating_mul(b as Weight)) + .saturating_add((9_838_000 as Weight).saturating_mul(b as Weight)) .saturating_add(RocksDbWeight::get().reads(1 as Weight)) .saturating_add(RocksDbWeight::get().reads((1 as Weight).saturating_mul(b as Weight))) .saturating_add(RocksDbWeight::get().writes(1 as Weight)) @@ -271,9 +302,9 @@ // Storage: Refungible Balance (r:0 w:4) // Storage: Refungible Owned (r:0 w:4) fn create_multiple_items_ex_multiple_owners(b: u32, ) -> Weight { - (1_980_000 as Weight) + (11_335_000 as Weight) // Standard Error: 2_000 - .saturating_add((6_305_000 as Weight).saturating_mul(b as Weight)) + .saturating_add((6_784_000 as Weight).saturating_mul(b as Weight)) .saturating_add(RocksDbWeight::get().reads(1 as Weight)) .saturating_add(RocksDbWeight::get().reads((1 as Weight).saturating_mul(b as Weight))) .saturating_add(RocksDbWeight::get().writes(3 as Weight)) @@ -284,7 +315,7 @@ // Storage: Refungible AccountBalance (r:1 w:1) // Storage: Refungible Owned (r:0 w:1) fn burn_item_partial() -> Weight { - (21_010_000 as Weight) + (21_239_000 as Weight) .saturating_add(RocksDbWeight::get().reads(3 as Weight)) .saturating_add(RocksDbWeight::get().writes(4 as Weight)) } @@ -294,14 +325,15 @@ // Storage: Refungible TokensBurnt (r:1 w:1) // Storage: Refungible TokenData (r:0 w:1) // Storage: Refungible Owned (r:0 w:1) + // Storage: Refungible TokenProperties (r:0 w:1) fn burn_item_fully() -> Weight { - (28_413_000 as Weight) + (29_426_000 as Weight) .saturating_add(RocksDbWeight::get().reads(4 as Weight)) - .saturating_add(RocksDbWeight::get().writes(6 as Weight)) + .saturating_add(RocksDbWeight::get().writes(7 as Weight)) } // Storage: Refungible Balance (r:2 w:2) fn transfer_normal() -> Weight { - (17_513_000 as Weight) + (17_743_000 as Weight) .saturating_add(RocksDbWeight::get().reads(2 as Weight)) .saturating_add(RocksDbWeight::get().writes(2 as Weight)) } @@ -309,7 +341,7 @@ // Storage: Refungible AccountBalance (r:1 w:1) // Storage: Refungible Owned (r:0 w:1) fn transfer_creating() -> Weight { - (20_469_000 as Weight) + (20_699_000 as Weight) .saturating_add(RocksDbWeight::get().reads(3 as Weight)) .saturating_add(RocksDbWeight::get().writes(4 as Weight)) } @@ -317,7 +349,7 @@ // Storage: Refungible AccountBalance (r:1 w:1) // Storage: Refungible Owned (r:0 w:1) fn transfer_removing() -> Weight { - (22_472_000 as Weight) + (22_833_000 as Weight) .saturating_add(RocksDbWeight::get().reads(3 as Weight)) .saturating_add(RocksDbWeight::get().writes(4 as Weight)) } @@ -325,21 +357,21 @@ // Storage: Refungible AccountBalance (r:2 w:2) // Storage: Refungible Owned (r:0 w:2) fn transfer_creating_removing() -> Weight { - (24_866_000 as Weight) + (24_936_000 as Weight) .saturating_add(RocksDbWeight::get().reads(4 as Weight)) .saturating_add(RocksDbWeight::get().writes(6 as Weight)) } // Storage: Refungible Balance (r:1 w:0) // Storage: Refungible Allowance (r:0 w:1) fn approve() -> Weight { - (13_475_000 as Weight) + (13_446_000 as Weight) .saturating_add(RocksDbWeight::get().reads(1 as Weight)) .saturating_add(RocksDbWeight::get().writes(1 as Weight)) } // Storage: Refungible Allowance (r:1 w:1) // Storage: Refungible Balance (r:2 w:2) fn transfer_from_normal() -> Weight { - (24_707_000 as Weight) + (24_777_000 as Weight) .saturating_add(RocksDbWeight::get().reads(3 as Weight)) .saturating_add(RocksDbWeight::get().writes(3 as Weight)) } @@ -348,7 +380,7 @@ // Storage: Refungible AccountBalance (r:1 w:1) // Storage: Refungible Owned (r:0 w:1) fn transfer_from_creating() -> Weight { - (27_812_000 as Weight) + (28_483_000 as Weight) .saturating_add(RocksDbWeight::get().reads(4 as Weight)) .saturating_add(RocksDbWeight::get().writes(5 as Weight)) } @@ -357,7 +389,7 @@ // Storage: Refungible AccountBalance (r:1 w:1) // Storage: Refungible Owned (r:0 w:1) fn transfer_from_removing() -> Weight { - (29_966_000 as Weight) + (29_896_000 as Weight) .saturating_add(RocksDbWeight::get().reads(4 as Weight)) .saturating_add(RocksDbWeight::get().writes(5 as Weight)) } @@ -366,7 +398,7 @@ // Storage: Refungible AccountBalance (r:2 w:2) // Storage: Refungible Owned (r:0 w:2) fn transfer_from_creating_removing() -> Weight { - (31_660_000 as Weight) + (32_070_000 as Weight) .saturating_add(RocksDbWeight::get().reads(5 as Weight)) .saturating_add(RocksDbWeight::get().writes(7 as Weight)) } @@ -377,15 +409,42 @@ // Storage: Refungible TokensBurnt (r:1 w:1) // Storage: Refungible TokenData (r:0 w:1) // Storage: Refungible Owned (r:0 w:1) + // Storage: Refungible TokenProperties (r:0 w:1) fn burn_from() -> Weight { - (36_248_000 as Weight) + (36_789_000 as Weight) .saturating_add(RocksDbWeight::get().reads(5 as Weight)) - .saturating_add(RocksDbWeight::get().writes(7 as Weight)) + .saturating_add(RocksDbWeight::get().writes(8 as Weight)) + } + // Storage: Common CollectionPropertyPermissions (r:1 w:1) + fn set_token_property_permissions(b: u32, ) -> Weight { + (0 as Weight) + // Standard Error: 62_000 + .saturating_add((15_803_000 as Weight).saturating_mul(b as Weight)) + .saturating_add(RocksDbWeight::get().reads(1 as Weight)) + .saturating_add(RocksDbWeight::get().writes(1 as Weight)) + } + // Storage: Common CollectionPropertyPermissions (r:1 w:0) + // Storage: Refungible TokenProperties (r:1 w:1) + fn set_token_properties(b: u32, ) -> Weight { + (0 as Weight) + // Standard Error: 1_668_000 + .saturating_add((302_308_000 as Weight).saturating_mul(b as Weight)) + .saturating_add(RocksDbWeight::get().reads(2 as Weight)) + .saturating_add(RocksDbWeight::get().writes(1 as Weight)) } + // Storage: Common CollectionPropertyPermissions (r:1 w:0) + // Storage: Refungible TokenProperties (r:1 w:1) + fn delete_token_properties(b: u32, ) -> Weight { + (0 as Weight) + // Standard Error: 1_619_000 + .saturating_add((294_574_000 as Weight).saturating_mul(b as Weight)) + .saturating_add(RocksDbWeight::get().reads(2 as Weight)) + .saturating_add(RocksDbWeight::get().writes(1 as Weight)) + } // Storage: Refungible TotalSupply (r:1 w:1) // Storage: Refungible Balance (r:1 w:1) fn repartition_item() -> Weight { - (8_226_000 as Weight) + (8_325_000 as Weight) .saturating_add(RocksDbWeight::get().reads(2 as Weight)) .saturating_add(RocksDbWeight::get().writes(2 as Weight)) } -- gitstuff