Introduce sensible weight constants (#12868)

* Introduce sensible weight constants

* cargo fmt

* Remove unused import

* Add missing import

* ".git/.scripts/bench-bot.sh" pallet dev pallet_lottery

Co-authored-by: command-bot <>
This commit is contained in:
Keith Yeung
2022-12-09 01:18:51 +09:00
committed by GitHub
parent 200f49d66d
commit 51db8c77a7
26 changed files with 140 additions and 113 deletions
@@ -69,7 +69,7 @@ The interesting part in the generated weight file tells us the weight constants
/// 99th: 18_270
/// 95th: 16_190
/// 75th: 14_819
read: 14_262 * constants::WEIGHT_PER_NANOS,
read: 14_262 * constants::WEIGHT_REF_TIME_PER_NANOS,
/// Time to write one storage item.
/// Calculated by multiplying the *Average* of all values with `1.1` and adding `0`.
@@ -84,7 +84,7 @@ read: 14_262 * constants::WEIGHT_PER_NANOS,
/// 99th: 135_839
/// 95th: 106_129
/// 75th: 79_239
write: 71_347 * constants::WEIGHT_PER_NANOS,
write: 71_347 * constants::WEIGHT_REF_TIME_PER_NANOS,
```
## Arguments
@@ -43,7 +43,7 @@ pub mod constants {
/// 99th: {{underscore read.0.p99}}
/// 95th: {{underscore read.0.p95}}
/// 75th: {{underscore read.0.p75}}
read: {{underscore read_weight}} * constants::WEIGHT_PER_NANOS,
read: {{underscore read_weight}} * constants::WEIGHT_REF_TIME_PER_NANOS,
/// Time to write one storage item.
/// Calculated by multiplying the *{{params.weight_params.weight_metric}}* of all values with `{{params.weight_params.weight_mul}}` and adding `{{params.weight_params.weight_add}}`.
@@ -58,7 +58,7 @@ pub mod constants {
/// 99th: {{underscore write.0.p99}}
/// 95th: {{underscore write.0.p95}}
/// 75th: {{underscore write.0.p75}}
write: {{underscore write_weight}} * constants::WEIGHT_PER_NANOS,
write: {{underscore write_weight}} * constants::WEIGHT_REF_TIME_PER_NANOS,
};
}
@@ -74,20 +74,20 @@ pub mod constants {
fn bound() {
// At least 1 µs.
assert!(
W::get().reads(1).ref_time() >= constants::WEIGHT_PER_MICROS.ref_time(),
W::get().reads(1).ref_time() >= constants::WEIGHT_REF_TIME_PER_MICROS,
"Read weight should be at least 1 µs."
);
assert!(
W::get().writes(1).ref_time() >= constants::WEIGHT_PER_MICROS.ref_time(),
W::get().writes(1).ref_time() >= constants::WEIGHT_REF_TIME_PER_MICROS,
"Write weight should be at least 1 µs."
);
// At most 1 ms.
assert!(
W::get().reads(1).ref_time() <= constants::WEIGHT_PER_MILLIS.ref_time(),
W::get().reads(1).ref_time() <= constants::WEIGHT_REF_TIME_PER_MILLIS,
"Read weight should be at most 1 ms."
);
assert!(
W::get().writes(1).ref_time() <= constants::WEIGHT_PER_MILLIS.ref_time(),
W::get().writes(1).ref_time() <= constants::WEIGHT_REF_TIME_PER_MILLIS,
"Write weight should be at most 1 ms."
);
}