Skip to content

Commit

Permalink
Stateful storage pov optimization (#1757)
Browse files Browse the repository at this point in the history
# Goal
The goal of this PR is to evaluate and minimize PoV consumption by
`stateful-storage` pallet.

Closes #1782 

# Discussion
- refactored benchmarks to calculate the max of time and PoV
- decreased `additional-trie-layers` number
- decreased `MaxItemizedPageSizeBytes ` from 64KiB to around 10KiB (will
allow around 292 of 32 bytes itemized public keys)

# Improvements
- by applying mentioned changes the PoV for `apply_item_actions` got
reduced from **45KB** to **15KB**
- by applying mentioned changes the PoV for `upsert` and `delete` pages
got reduced from **12KB** to **6KB**

# Future improvements
- by using PoV clawback we can further reduce the PoV sizes. A
[PR](paritytech/polkadot-sdk#1462) to track

# Checklist
- [x] Benchmarks added
- [x] Weights updated

---------

Co-authored-by: Frequency CI [bot] <do-not-reply@users.noreply.github.com>
Co-authored-by: Wil Wade <wil.wade@unfinished.com>
  • Loading branch information
3 people authored Nov 16, 2023
1 parent 2299186 commit 64e27b7
Show file tree
Hide file tree
Showing 27 changed files with 1,084 additions and 919 deletions.
62 changes: 31 additions & 31 deletions pallets/capacity/src/weights.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@
//! Autogenerated weights for pallet_capacity
//!
//! THIS FILE WAS AUTO-GENERATED USING THE SUBSTRATE BENCHMARK CLI VERSION 4.0.0-dev
//! DATE: 2023-10-30, STEPS: `20`, REPEAT: `10`, LOW RANGE: `[]`, HIGH RANGE: `[]`
//! DATE: 2023-11-14, STEPS: `20`, REPEAT: `10`, LOW RANGE: `[]`, HIGH RANGE: `[]`
//! WORST CASE MAP SIZE: `1000000`
//! HOSTNAME: `benchmark-runner-44wtw-bw25f`, CPU: `Intel(R) Xeon(R) Platinum 8375C CPU @ 2.90GHz`
//! HOSTNAME: `benchmark-runner-44wtw-sz2gt`, CPU: `Intel(R) Xeon(R) Platinum 8375C CPU @ 2.90GHz`
//! EXECUTION: , WASM-EXECUTION: Compiled, CHAIN: Some("frequency-bench"), DB CACHE: 1024
// Executed Command:
Expand All @@ -33,7 +33,7 @@
// --chain=frequency-bench
// --heap-pages=4096
// --wasm-execution=compiled
// --additional-trie-layers=20
// --additional-trie-layers=5
// --steps=20
// --repeat=10
// --output=./scripts/../pallets/capacity/src/weights.rs
Expand Down Expand Up @@ -74,9 +74,9 @@ impl<T: frame_system::Config> WeightInfo for SubstrateWeight<T> {
fn stake() -> Weight {
// Proof Size summary in bytes:
// Measured: `223`
// Estimated: `13674`
// Minimum execution time: 43_127_000 picoseconds.
Weight::from_parts(44_191_000, 13674)
// Estimated: `6249`
// Minimum execution time: 43_154_000 picoseconds.
Weight::from_parts(44_525_000, 6249)
.saturating_add(T::DbWeight::get().reads(6_u64))
.saturating_add(T::DbWeight::get().writes(4_u64))
}
Expand All @@ -89,9 +89,9 @@ impl<T: frame_system::Config> WeightInfo for SubstrateWeight<T> {
fn withdraw_unstaked() -> Weight {
// Proof Size summary in bytes:
// Measured: `339`
// Estimated: `13674`
// Minimum execution time: 33_146_000 picoseconds.
Weight::from_parts(34_058_000, 13674)
// Estimated: `6249`
// Minimum execution time: 33_031_000 picoseconds.
Weight::from_parts(34_284_000, 6249)
.saturating_add(T::DbWeight::get().reads(3_u64))
.saturating_add(T::DbWeight::get().writes(2_u64))
}
Expand All @@ -102,9 +102,9 @@ impl<T: frame_system::Config> WeightInfo for SubstrateWeight<T> {
fn on_initialize() -> Weight {
// Proof Size summary in bytes:
// Measured: `0`
// Estimated: `10399`
// Minimum execution time: 4_040_000 picoseconds.
Weight::from_parts(4_215_000, 10399)
// Estimated: `2974`
// Minimum execution time: 3_876_000 picoseconds.
Weight::from_parts(4_036_000, 2974)
.saturating_add(T::DbWeight::get().reads(2_u64))
.saturating_add(T::DbWeight::get().writes(1_u64))
}
Expand All @@ -121,9 +121,9 @@ impl<T: frame_system::Config> WeightInfo for SubstrateWeight<T> {
fn unstake() -> Weight {
// Proof Size summary in bytes:
// Measured: `433`
// Estimated: `13674`
// Minimum execution time: 38_156_000 picoseconds.
Weight::from_parts(39_905_000, 13674)
// Estimated: `6249`
// Minimum execution time: 38_465_000 picoseconds.
Weight::from_parts(39_656_000, 6249)
.saturating_add(T::DbWeight::get().reads(5_u64))
.saturating_add(T::DbWeight::get().writes(4_u64))
}
Expand All @@ -133,8 +133,8 @@ impl<T: frame_system::Config> WeightInfo for SubstrateWeight<T> {
// Proof Size summary in bytes:
// Measured: `0`
// Estimated: `0`
// Minimum execution time: 6_429_000 picoseconds.
Weight::from_parts(6_896_000, 0)
// Minimum execution time: 6_805_000 picoseconds.
Weight::from_parts(7_569_000, 0)
.saturating_add(T::DbWeight::get().writes(1_u64))
}
}
Expand All @@ -156,9 +156,9 @@ impl WeightInfo for () {
fn stake() -> Weight {
// Proof Size summary in bytes:
// Measured: `223`
// Estimated: `13674`
// Minimum execution time: 43_127_000 picoseconds.
Weight::from_parts(44_191_000, 13674)
// Estimated: `6249`
// Minimum execution time: 43_154_000 picoseconds.
Weight::from_parts(44_525_000, 6249)
.saturating_add(RocksDbWeight::get().reads(6_u64))
.saturating_add(RocksDbWeight::get().writes(4_u64))
}
Expand All @@ -171,9 +171,9 @@ impl WeightInfo for () {
fn withdraw_unstaked() -> Weight {
// Proof Size summary in bytes:
// Measured: `339`
// Estimated: `13674`
// Minimum execution time: 33_146_000 picoseconds.
Weight::from_parts(34_058_000, 13674)
// Estimated: `6249`
// Minimum execution time: 33_031_000 picoseconds.
Weight::from_parts(34_284_000, 6249)
.saturating_add(RocksDbWeight::get().reads(3_u64))
.saturating_add(RocksDbWeight::get().writes(2_u64))
}
Expand All @@ -184,9 +184,9 @@ impl WeightInfo for () {
fn on_initialize() -> Weight {
// Proof Size summary in bytes:
// Measured: `0`
// Estimated: `10399`
// Minimum execution time: 4_040_000 picoseconds.
Weight::from_parts(4_215_000, 10399)
// Estimated: `2974`
// Minimum execution time: 3_876_000 picoseconds.
Weight::from_parts(4_036_000, 2974)
.saturating_add(RocksDbWeight::get().reads(2_u64))
.saturating_add(RocksDbWeight::get().writes(1_u64))
}
Expand All @@ -203,9 +203,9 @@ impl WeightInfo for () {
fn unstake() -> Weight {
// Proof Size summary in bytes:
// Measured: `433`
// Estimated: `13674`
// Minimum execution time: 38_156_000 picoseconds.
Weight::from_parts(39_905_000, 13674)
// Estimated: `6249`
// Minimum execution time: 38_465_000 picoseconds.
Weight::from_parts(39_656_000, 6249)
.saturating_add(RocksDbWeight::get().reads(5_u64))
.saturating_add(RocksDbWeight::get().writes(4_u64))
}
Expand All @@ -215,8 +215,8 @@ impl WeightInfo for () {
// Proof Size summary in bytes:
// Measured: `0`
// Estimated: `0`
// Minimum execution time: 6_429_000 picoseconds.
Weight::from_parts(6_896_000, 0)
// Minimum execution time: 6_805_000 picoseconds.
Weight::from_parts(7_569_000, 0)
.saturating_add(RocksDbWeight::get().writes(1_u64))
}
}
30 changes: 15 additions & 15 deletions pallets/frequency-tx-payment/src/weights.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@
//! Autogenerated weights for pallet_frequency_tx_payment
//!
//! THIS FILE WAS AUTO-GENERATED USING THE SUBSTRATE BENCHMARK CLI VERSION 4.0.0-dev
//! DATE: 2023-10-30, STEPS: `20`, REPEAT: `10`, LOW RANGE: `[]`, HIGH RANGE: `[]`
//! DATE: 2023-11-14, STEPS: `20`, REPEAT: `10`, LOW RANGE: `[]`, HIGH RANGE: `[]`
//! WORST CASE MAP SIZE: `1000000`
//! HOSTNAME: `benchmark-runner-44wtw-bw25f`, CPU: `Intel(R) Xeon(R) Platinum 8375C CPU @ 2.90GHz`
//! HOSTNAME: `benchmark-runner-44wtw-sz2gt`, CPU: `Intel(R) Xeon(R) Platinum 8375C CPU @ 2.90GHz`
//! EXECUTION: , WASM-EXECUTION: Compiled, CHAIN: Some("frequency-bench"), DB CACHE: 1024
// Executed Command:
Expand All @@ -33,7 +33,7 @@
// --chain=frequency-bench
// --heap-pages=4096
// --wasm-execution=compiled
// --additional-trie-layers=20
// --additional-trie-layers=5
// --steps=20
// --repeat=10
// --output=./scripts/../pallets/frequency-tx-payment/src/weights.rs
Expand All @@ -60,18 +60,18 @@ impl<T: frame_system::Config> WeightInfo for SubstrateWeight<T> {
// Proof Size summary in bytes:
// Measured: `0`
// Estimated: `0`
// Minimum execution time: 3_362_000 picoseconds.
Weight::from_parts(3_551_000, 0)
// Minimum execution time: 3_294_000 picoseconds.
Weight::from_parts(3_499_000, 0)
}
/// The range of component `n` is `[0, 10]`.
fn pay_with_capacity_batch_all(n: u32, ) -> Weight {
// Proof Size summary in bytes:
// Measured: `0`
// Estimated: `0`
// Minimum execution time: 7_061_000 picoseconds.
Weight::from_parts(8_127_386, 0)
// Standard Error: 16_699
.saturating_add(Weight::from_parts(4_653_714, 0).saturating_mul(n.into()))
// Minimum execution time: 7_318_000 picoseconds.
Weight::from_parts(8_276_383, 0)
// Standard Error: 12_166
.saturating_add(Weight::from_parts(4_732_333, 0).saturating_mul(n.into()))
}
}

Expand All @@ -81,17 +81,17 @@ impl WeightInfo for () {
// Proof Size summary in bytes:
// Measured: `0`
// Estimated: `0`
// Minimum execution time: 3_362_000 picoseconds.
Weight::from_parts(3_551_000, 0)
// Minimum execution time: 3_294_000 picoseconds.
Weight::from_parts(3_499_000, 0)
}
/// The range of component `n` is `[0, 10]`.
fn pay_with_capacity_batch_all(n: u32, ) -> Weight {
// Proof Size summary in bytes:
// Measured: `0`
// Estimated: `0`
// Minimum execution time: 7_061_000 picoseconds.
Weight::from_parts(8_127_386, 0)
// Standard Error: 16_699
.saturating_add(Weight::from_parts(4_653_714, 0).saturating_mul(n.into()))
// Minimum execution time: 7_318_000 picoseconds.
Weight::from_parts(8_276_383, 0)
// Standard Error: 12_166
.saturating_add(Weight::from_parts(4_732_333, 0).saturating_mul(n.into()))
}
}
58 changes: 29 additions & 29 deletions pallets/handles/src/weights.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@
//! Autogenerated weights for pallet_handles
//!
//! THIS FILE WAS AUTO-GENERATED USING THE SUBSTRATE BENCHMARK CLI VERSION 4.0.0-dev
//! DATE: 2023-10-30, STEPS: `20`, REPEAT: `10`, LOW RANGE: `[]`, HIGH RANGE: `[]`
//! DATE: 2023-11-14, STEPS: `20`, REPEAT: `10`, LOW RANGE: `[]`, HIGH RANGE: `[]`
//! WORST CASE MAP SIZE: `1000000`
//! HOSTNAME: `benchmark-runner-44wtw-bw25f`, CPU: `Intel(R) Xeon(R) Platinum 8375C CPU @ 2.90GHz`
//! HOSTNAME: `benchmark-runner-44wtw-sz2gt`, CPU: `Intel(R) Xeon(R) Platinum 8375C CPU @ 2.90GHz`
//! EXECUTION: , WASM-EXECUTION: Compiled, CHAIN: Some("frequency-bench"), DB CACHE: 1024
// Executed Command:
Expand All @@ -33,7 +33,7 @@
// --chain=frequency-bench
// --heap-pages=4096
// --wasm-execution=compiled
// --additional-trie-layers=20
// --additional-trie-layers=5
// --steps=20
// --repeat=10
// --output=./scripts/../pallets/handles/src/weights.rs
Expand Down Expand Up @@ -69,11 +69,11 @@ impl<T: frame_system::Config> WeightInfo for SubstrateWeight<T> {
fn claim_handle(b: u32, ) -> Weight {
// Proof Size summary in bytes:
// Measured: `191`
// Estimated: `12434`
// Minimum execution time: 81_465_000 picoseconds.
Weight::from_parts(83_332_398, 12434)
// Standard Error: 9_174
.saturating_add(Weight::from_parts(77_143, 0).saturating_mul(b.into()))
// Estimated: `5009`
// Minimum execution time: 82_418_000 picoseconds.
Weight::from_parts(84_250_657, 5009)
// Standard Error: 18_982
.saturating_add(Weight::from_parts(75_863, 0).saturating_mul(b.into()))
.saturating_add(T::DbWeight::get().reads(3_u64))
.saturating_add(T::DbWeight::get().writes(3_u64))
}
Expand All @@ -89,11 +89,11 @@ impl<T: frame_system::Config> WeightInfo for SubstrateWeight<T> {
fn change_handle(b: u32, ) -> Weight {
// Proof Size summary in bytes:
// Measured: `297 + b * (1 ±0)`
// Estimated: `12434`
// Minimum execution time: 91_552_000 picoseconds.
Weight::from_parts(93_641_136, 12434)
// Standard Error: 10_045
.saturating_add(Weight::from_parts(152_851, 0).saturating_mul(b.into()))
// Estimated: `5009`
// Minimum execution time: 93_554_000 picoseconds.
Weight::from_parts(94_507_705, 5009)
// Standard Error: 8_136
.saturating_add(Weight::from_parts(165_626, 0).saturating_mul(b.into()))
.saturating_add(T::DbWeight::get().reads(3_u64))
.saturating_add(T::DbWeight::get().writes(4_u64))
}
Expand All @@ -106,9 +106,9 @@ impl<T: frame_system::Config> WeightInfo for SubstrateWeight<T> {
fn retire_handle() -> Weight {
// Proof Size summary in bytes:
// Measured: `306`
// Estimated: `12434`
// Minimum execution time: 22_019_000 picoseconds.
Weight::from_parts(22_866_000, 12434)
// Estimated: `5009`
// Minimum execution time: 22_739_000 picoseconds.
Weight::from_parts(23_360_000, 5009)
.saturating_add(T::DbWeight::get().reads(2_u64))
.saturating_add(T::DbWeight::get().writes(2_u64))
}
Expand All @@ -128,11 +128,11 @@ impl WeightInfo for () {
fn claim_handle(b: u32, ) -> Weight {
// Proof Size summary in bytes:
// Measured: `191`
// Estimated: `12434`
// Minimum execution time: 81_465_000 picoseconds.
Weight::from_parts(83_332_398, 12434)
// Standard Error: 9_174
.saturating_add(Weight::from_parts(77_143, 0).saturating_mul(b.into()))
// Estimated: `5009`
// Minimum execution time: 82_418_000 picoseconds.
Weight::from_parts(84_250_657, 5009)
// Standard Error: 18_982
.saturating_add(Weight::from_parts(75_863, 0).saturating_mul(b.into()))
.saturating_add(RocksDbWeight::get().reads(3_u64))
.saturating_add(RocksDbWeight::get().writes(3_u64))
}
Expand All @@ -148,11 +148,11 @@ impl WeightInfo for () {
fn change_handle(b: u32, ) -> Weight {
// Proof Size summary in bytes:
// Measured: `297 + b * (1 ±0)`
// Estimated: `12434`
// Minimum execution time: 91_552_000 picoseconds.
Weight::from_parts(93_641_136, 12434)
// Standard Error: 10_045
.saturating_add(Weight::from_parts(152_851, 0).saturating_mul(b.into()))
// Estimated: `5009`
// Minimum execution time: 93_554_000 picoseconds.
Weight::from_parts(94_507_705, 5009)
// Standard Error: 8_136
.saturating_add(Weight::from_parts(165_626, 0).saturating_mul(b.into()))
.saturating_add(RocksDbWeight::get().reads(3_u64))
.saturating_add(RocksDbWeight::get().writes(4_u64))
}
Expand All @@ -165,9 +165,9 @@ impl WeightInfo for () {
fn retire_handle() -> Weight {
// Proof Size summary in bytes:
// Measured: `306`
// Estimated: `12434`
// Minimum execution time: 22_019_000 picoseconds.
Weight::from_parts(22_866_000, 12434)
// Estimated: `5009`
// Minimum execution time: 22_739_000 picoseconds.
Weight::from_parts(23_360_000, 5009)
.saturating_add(RocksDbWeight::get().reads(2_u64))
.saturating_add(RocksDbWeight::get().writes(2_u64))
}
Expand Down
Loading

0 comments on commit 64e27b7

Please sign in to comment.