mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-06-14 05:11:09 +00:00
Refactor weight constants, Update to remove redundant overhead (#5884)
* Move weight values to `frame_support` * more accurate comment * update balances * vesting * update util * Add weight to time constants * use weight constants in weights * update tests
This commit is contained in:
@@ -432,11 +432,11 @@ decl_module! {
|
||||
/// - `transfer_keep_alive` works the same way as `transfer`, but has an additional
|
||||
/// check that the transfer will not kill the origin account.
|
||||
/// ---------------------------------
|
||||
/// - Base Weight: 80 µs, worst case scenario (account created, account removed)
|
||||
/// - Base Weight: 73.64 µs, worst case scenario (account created, account removed)
|
||||
/// - DB Weight: 1 Read and 1 Write to destination account
|
||||
/// - Origin account is already in memory, so no DB operations for them.
|
||||
/// # </weight>
|
||||
#[weight = T::DbWeight::get().reads_writes(1, 1) + 80_000_000]
|
||||
#[weight = T::DbWeight::get().reads_writes(1, 1) + 70_000_000]
|
||||
pub fn transfer(
|
||||
origin,
|
||||
dest: <T::Lookup as StaticLookup>::Source,
|
||||
@@ -460,7 +460,9 @@ decl_module! {
|
||||
/// - Independent of the arguments.
|
||||
/// - Contains a limited number of reads and writes.
|
||||
/// ---------------------
|
||||
/// - Base Weight: 32.6 µs
|
||||
/// - Base Weight:
|
||||
/// - Creating: 27.56 µs
|
||||
/// - Killing: 35.11 µs
|
||||
/// - DB Weight: 1 Read, 1 Write to `who`
|
||||
/// # </weight>
|
||||
#[weight = T::DbWeight::get().reads_writes(1, 1) + 35_000_000]
|
||||
@@ -505,7 +507,7 @@ decl_module! {
|
||||
/// - Same as transfer, but additional read and write because the source account is
|
||||
/// not assumed to be in the overlay.
|
||||
/// # </weight>
|
||||
#[weight = T::DbWeight::get().reads_writes(2, 2) + 80_000_000]
|
||||
#[weight = T::DbWeight::get().reads_writes(2, 2) + 70_000_000]
|
||||
pub fn force_transfer(
|
||||
origin,
|
||||
source: <T::Lookup as StaticLookup>::Source,
|
||||
@@ -526,10 +528,10 @@ decl_module! {
|
||||
/// [`transfer`]: struct.Module.html#method.transfer
|
||||
/// # <weight>
|
||||
/// - Cheaper than transfer because account cannot be killed.
|
||||
/// - Base Weight: 57.36 µs
|
||||
/// - Base Weight: 51.4 µs
|
||||
/// - DB Weight: 1 Read and 1 Write to dest (sender is in overlay already)
|
||||
/// #</weight>
|
||||
#[weight = T::DbWeight::get().reads_writes(1, 1) + 60_000_000]
|
||||
#[weight = T::DbWeight::get().reads_writes(1, 1) + 50_000_000]
|
||||
pub fn transfer_keep_alive(
|
||||
origin,
|
||||
dest: <T::Lookup as StaticLookup>::Source,
|
||||
|
||||
@@ -141,6 +141,37 @@ pub use sp_runtime::transaction_validity::TransactionPriority;
|
||||
/// Numeric range of a transaction weight.
|
||||
pub type Weight = u64;
|
||||
|
||||
/// These constants are specific to FRAME, and the current implementation of its various components.
|
||||
/// For example: FRAME System, FRAME Executive, our FRAME support libraries, etc...
|
||||
pub mod constants {
|
||||
use super::{RuntimeDbWeight, Weight};
|
||||
use crate::parameter_types;
|
||||
|
||||
pub const WEIGHT_PER_SECOND: Weight = 1_000_000_000_000;
|
||||
pub const WEIGHT_PER_MILLIS: Weight = WEIGHT_PER_SECOND / 1000; // 1_000_000_000
|
||||
pub const WEIGHT_PER_MICROS: Weight = WEIGHT_PER_MILLIS / 1000; // 1_000_000
|
||||
pub const WEIGHT_PER_NANOS: Weight = WEIGHT_PER_MICROS / 1000; // 1_000
|
||||
|
||||
parameter_types! {
|
||||
/// Importing a block with 0 txs takes ~5 ms
|
||||
pub const BlockExecutionWeight: Weight = 5 * WEIGHT_PER_MILLIS;
|
||||
/// Executing 10,000 System remarks (no-op) txs takes ~1.26 seconds -> ~125 µs per tx
|
||||
pub const ExtrinsicBaseWeight: Weight = 125 * WEIGHT_PER_MICROS;
|
||||
/// By default, Substrate uses RocksDB, so this will be the weight used throughout
|
||||
/// the runtime.
|
||||
pub const RocksDbWeight: RuntimeDbWeight = RuntimeDbWeight {
|
||||
read: 25 * WEIGHT_PER_MICROS, // ~25 µs @ 200,000 items
|
||||
write: 100 * WEIGHT_PER_MICROS, // ~100 µs @ 200,000 items
|
||||
};
|
||||
/// ParityDB can be enabled with a feature flag, but is still experimental. These weights
|
||||
/// are available for brave runtime engineers who may want to try this out as default.
|
||||
pub const ParityDbWeight: RuntimeDbWeight = RuntimeDbWeight {
|
||||
read: 8 * WEIGHT_PER_MICROS, // ~8 µs @ 200,000 items
|
||||
write: 50 * WEIGHT_PER_MICROS, // ~50 µs @ 200,000 items
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
/// Means of weighing some particular kind of data (`T`).
|
||||
pub trait WeighData<T> {
|
||||
/// Weigh the data `T` given by `target`. When implementing this for a dispatchable, `T` will be
|
||||
|
||||
@@ -205,16 +205,16 @@ mod weight_of {
|
||||
use super::*;
|
||||
|
||||
/// - Base Weight:
|
||||
/// - Create: 59.2 + 0.096 * S µs
|
||||
/// - Approve: 42.27 + .116 * S µs
|
||||
/// - Complete: 50.91 + .232 * S µs
|
||||
/// - Create: 46.55 + 0.089 * S µs
|
||||
/// - Approve: 34.03 + .112 * S µs
|
||||
/// - Complete: 40.36 + .225 * S µs
|
||||
/// - DB Weight:
|
||||
/// - Reads: Multisig Storage, [Caller Account]
|
||||
/// - Writes: Multisig Storage, [Caller Account]
|
||||
/// - Plus Call Weight
|
||||
pub fn as_multi<T: Trait>(other_sig_len: usize, call_weight: Weight) -> Weight {
|
||||
call_weight
|
||||
.saturating_add(60_000_000)
|
||||
.saturating_add(45_000_000)
|
||||
.saturating_add((other_sig_len as Weight).saturating_mul(250_000))
|
||||
.saturating_add(T::DbWeight::get().reads_writes(1, 1))
|
||||
}
|
||||
@@ -236,7 +236,7 @@ decl_module! {
|
||||
/// - `calls`: The calls to be dispatched from the same origin.
|
||||
///
|
||||
/// # <weight>
|
||||
/// - Base weight: 15.64 + .987 * c µs
|
||||
/// - Base weight: 14.39 + .987 * c µs
|
||||
/// - Plus the sum of the weights of the `calls`.
|
||||
/// - Plus one additional event. (repeat read/write)
|
||||
/// # </weight>
|
||||
@@ -280,7 +280,7 @@ decl_module! {
|
||||
/// The dispatch origin for this call must be _Signed_.
|
||||
///
|
||||
/// # <weight>
|
||||
/// - Base weight: 2.863 µs
|
||||
/// - Base weight: 2.861 µs
|
||||
/// - Plus the weight of the `call`
|
||||
/// # </weight>
|
||||
#[weight = FunctionOf(
|
||||
@@ -339,9 +339,9 @@ decl_module! {
|
||||
/// `MultisigDepositBase + threshold * MultisigDepositFactor`.
|
||||
/// -------------------------------
|
||||
/// - Base Weight:
|
||||
/// - Create: 59.2 + 0.096 * S µs
|
||||
/// - Approve: 42.27 + .116 * S µs
|
||||
/// - Complete: 50.91 + .232 * S µs
|
||||
/// - Create: 46.55 + 0.089 * S µs
|
||||
/// - Approve: 34.03 + .112 * S µs
|
||||
/// - Complete: 40.36 + .225 * S µs
|
||||
/// - DB Weight:
|
||||
/// - Reads: Multisig Storage, [Caller Account]
|
||||
/// - Writes: Multisig Storage, [Caller Account]
|
||||
@@ -471,8 +471,8 @@ decl_module! {
|
||||
/// `MultisigDepositBase + threshold * MultisigDepositFactor`.
|
||||
/// ----------------------------------
|
||||
/// - Base Weight:
|
||||
/// - Create: 56.3 + 0.107 * S
|
||||
/// - Approve: 39.25 + 0.121 * S
|
||||
/// - Create: 44.71 + 0.088 * S
|
||||
/// - Approve: 31.48 + 0.116 * S
|
||||
/// - DB Weight:
|
||||
/// - Read: Multisig Storage, [Caller Account]
|
||||
/// - Write: Multisig Storage, [Caller Account]
|
||||
@@ -480,7 +480,7 @@ decl_module! {
|
||||
#[weight = FunctionOf(
|
||||
|args: (&u16, &Vec<T::AccountId>, &Option<Timepoint<T::BlockNumber>>, &[u8; 32])| {
|
||||
T::DbWeight::get().reads_writes(1, 1)
|
||||
.saturating_add(60_000_000)
|
||||
.saturating_add(45_000_000)
|
||||
.saturating_add((args.1.len() as Weight).saturating_mul(120_000))
|
||||
},
|
||||
DispatchClass::Normal,
|
||||
@@ -554,7 +554,7 @@ decl_module! {
|
||||
/// - I/O: 1 read `O(S)`, one remove.
|
||||
/// - Storage: removes one item.
|
||||
/// ----------------------------------
|
||||
/// - Base Weight: 46.71 + 0.09 * S
|
||||
/// - Base Weight: 37.6 + 0.084 * S
|
||||
/// - DB Weight:
|
||||
/// - Read: Multisig Storage, [Caller Account]
|
||||
/// - Write: Multisig Storage, [Caller Account]
|
||||
@@ -562,7 +562,7 @@ decl_module! {
|
||||
#[weight = FunctionOf(
|
||||
|args: (&u16, &Vec<T::AccountId>, &Timepoint<T::BlockNumber>, &[u8; 32])| {
|
||||
T::DbWeight::get().reads_writes(1, 1)
|
||||
.saturating_add(50_000_000)
|
||||
.saturating_add(40_000_000)
|
||||
.saturating_add((args.1.len() as Weight).saturating_mul(100_000))
|
||||
},
|
||||
DispatchClass::Normal,
|
||||
|
||||
@@ -194,11 +194,11 @@ decl_module! {
|
||||
/// - Reads: Vesting Storage, Balances Locks, [Sender Account]
|
||||
/// - Writes: Vesting Storage, Balances Locks, [Sender Account]
|
||||
/// - Benchmark:
|
||||
/// - Unlocked: 56.1 + .098 * l µs (min square analysis)
|
||||
/// - Locked: 54.37 + .254 * l µs (min square analysis)
|
||||
/// - Using 60 µs fixed. Assuming less than 50 locks on any user, else we may want factor in number of locks.
|
||||
/// - Unlocked: 48.76 + .048 * l µs (min square analysis)
|
||||
/// - Locked: 44.43 + .284 * l µs (min square analysis)
|
||||
/// - Using 50 µs fixed. Assuming less than 50 locks on any user, else we may want factor in number of locks.
|
||||
/// # </weight>
|
||||
#[weight = 60_000_000 + T::DbWeight::get().reads_writes(2, 2)]
|
||||
#[weight = 50_000_000 + T::DbWeight::get().reads_writes(2, 2)]
|
||||
fn vest(origin) -> DispatchResult {
|
||||
let who = ensure_signed(origin)?;
|
||||
Self::update_lock(who)
|
||||
@@ -219,11 +219,11 @@ decl_module! {
|
||||
/// - Reads: Vesting Storage, Balances Locks, Target Account
|
||||
/// - Writes: Vesting Storage, Balances Locks, Target Account
|
||||
/// - Benchmark:
|
||||
/// - Unlocked: 58.09 + .104 * l µs (min square analysis)
|
||||
/// - Locked: 55.35 + .255 * l µs (min square analysis)
|
||||
/// - Using 60 µs fixed. Assuming less than 50 locks on any user, else we may want factor in number of locks.
|
||||
/// - Unlocked: 44.3 + .294 * l µs (min square analysis)
|
||||
/// - Locked: 48.16 + .103 * l µs (min square analysis)
|
||||
/// - Using 50 µs fixed. Assuming less than 50 locks on any user, else we may want factor in number of locks.
|
||||
/// # </weight>
|
||||
#[weight = 60_000_000 + T::DbWeight::get().reads_writes(3, 3)]
|
||||
#[weight = 50_000_000 + T::DbWeight::get().reads_writes(3, 3)]
|
||||
fn vest_other(origin, target: <T::Lookup as StaticLookup>::Source) -> DispatchResult {
|
||||
ensure_signed(origin)?;
|
||||
Self::update_lock(T::Lookup::lookup(target)?)
|
||||
@@ -244,10 +244,10 @@ decl_module! {
|
||||
/// - DbWeight: 3 Reads, 3 Writes
|
||||
/// - Reads: Vesting Storage, Balances Locks, Target Account, [Sender Account]
|
||||
/// - Writes: Vesting Storage, Balances Locks, Target Account, [Sender Account]
|
||||
/// - Benchmark: 111.4 + .345 * l µs (min square analysis)
|
||||
/// - Using 115 µs fixed. Assuming less than 50 locks on any user, else we may want factor in number of locks.
|
||||
/// - Benchmark: 100.3 + .365 * l µs (min square analysis)
|
||||
/// - Using 100 µs fixed. Assuming less than 50 locks on any user, else we may want factor in number of locks.
|
||||
/// # </weight>
|
||||
#[weight = 115_000_000 + T::DbWeight::get().reads_writes(3, 3)]
|
||||
#[weight = 100_000_000 + T::DbWeight::get().reads_writes(3, 3)]
|
||||
pub fn vested_transfer(
|
||||
origin,
|
||||
target: <T::Lookup as StaticLookup>::Source,
|
||||
|
||||
Reference in New Issue
Block a user