Skip to content

Commit bc42349

Browse files
sigurpolgithub-actions[bot]bkchr
authored
frame-omni-bencher: enable jemalloc-allocator (#11069)
Fix huge benchmark regression for storage-heavy extrinsics, enabling jemalloc-allocator via polkadot-jemalloc-shim for omni-bencher, marked as optional in the scope of PR #10590. This close paritytech/trie#230. Thanks @alexggh and @cheme for the help 🙇 Tested against `runtime / main` and [2.1.0](polkadot-fellows/runtimes#1065) as described [here](paritytech/trie#230 (comment)). For the `usual` exstrinsic `force_apply_min_commission` doing massive storage allocation/deallocation on benchmark setup and then just 1read - 2 write in the benchmark extrinsic itself, times goes down from ms to µs. The regression was introduced by #10590 `sc-client-db: Make jemalloc optional` ```bash runtimes git:(sigurpol-release-2_0_6) /home/paolo/github/polkadot-sdk/target/release/frame-omni-bencher v1 benchmark pallet --runtime ./target/release/wbuild/asset-hub-polkadot-runtime/asset_hub_polkadot_runtime.compact.compressed.wasm --pallet pallet_staking_async --extrinsic "force_apply_min_commission" --steps 2 --repeat 1 2026-02-13T15:06:30.145367Z INFO frame::benchmark::pallet: Initialized runtime log filter to 'INFO' 2026-02-13T15:06:31.784936Z INFO pallet_collator_selection::pallet: assembling new collators for new session 0 at #0 2026-02-13T15:06:31.784966Z INFO pallet_collator_selection::pallet: assembling new collators for new session 1 at #0 2026-02-13T15:08:29.701636Z INFO frame::benchmark::pallet: [ 0 % ] Starting benchmark: pallet_staking_async::force_apply_min_commission 2026-02-13T15:08:35.130403Z INFO frame::benchmark::pallet: [ 0 % ] Running benchmark: pallet_staking_async::force_apply_min_commission (overtime) Pallet: "pallet_staking_async", Extrinsic: "force_apply_min_commission", Lowest values: [], Highest values: [], Steps: 2, Repeat: 1 Raw Storage Info ======== Storage: `Staking::MinCommission` (r:1 w:0) Proof: `Staking::MinCommission` (`max_values`: Some(1), `max_size`: Some(4), added: 499, mode: `MaxEncodedLen`) Storage: `Staking::Validators` (r:1 w:1) Proof: `Staking::Validators` (`max_values`: None, `max_size`: Some(45), added: 2520, mode: `MaxEncodedLen`) Median Slopes Analysis ======== -- Extrinsic Time -- Model: Time ~= 50.31 µs Reads = 2 Writes = 1 Recorded proof Size = 564 Min Squares Analysis ======== -- Extrinsic Time -- Model: Time ~= 50.31 µs Reads = 2 Writes = 1 Recorded proof Size = 564 ``` --------- Co-authored-by: cmd[bot] <41898282+github-actions[bot]@users.noreply.github.com> Co-authored-by: Bastian Köcher <git@kchr.de>
1 parent dfb5c4b commit bc42349

File tree

4 files changed

+17
-13
lines changed

4 files changed

+17
-13
lines changed

Cargo.lock

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

prdoc/pr_11069.prdoc

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
title: 'frame-omni-bencher: enable jemalloc-allocator'
2+
doc:
3+
- audience: Runtime Dev
4+
description: |-
5+
Fix huge benchmark regression for storage-heavy extrinsics, enabling jemalloc-allocator via polkadot-jemalloc-shim for omni-bencher, marked as optional in the scope of PR #10590.
6+
Revert also the dummy write/read workaround at the end of commit_db() introduced by #10947.
7+
crates:
8+
- name: frame-omni-bencher
9+
bump: patch
10+
- name: frame-benchmarking
11+
bump: patch

substrate/frame/benchmarking/src/utils.rs

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -290,19 +290,6 @@ pub trait Benchmarking {
290290
/// Commit pending storage changes to the trie database and clear the database cache.
291291
fn commit_db(&mut self) {
292292
self.commit();
293-
294-
// Warmup the memory allocator after bulk deallocation.
295-
// After draining the overlay with many entries, the first new allocation can trigger memory
296-
// defragmentation. The warmup key is whitelisted so these operations don't appear in
297-
// benchmark results.
298-
const WARMUP_KEY: &[u8] = b":benchmark_warmup:";
299-
let mut whitelist = self.get_whitelist();
300-
if !whitelist.iter().any(|k| k.key == WARMUP_KEY) {
301-
whitelist.push(WARMUP_KEY.to_vec().into());
302-
self.set_whitelist(whitelist);
303-
}
304-
self.place_storage(WARMUP_KEY.to_vec(), Some(vec![0u8; 32]));
305-
self.place_storage(WARMUP_KEY.to_vec(), None);
306293
}
307294

308295
/// Get the read/write count.

substrate/utils/frame/omni-bencher/Cargo.toml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,16 @@ workspace = true
1515
clap = { features = ["derive"], workspace = true }
1616
cumulus-primitives-proof-size-hostfunction = { workspace = true, default-features = true }
1717
frame-benchmarking-cli = { workspace = true }
18+
polkadot-jemalloc-shim = { workspace = true }
1819
sc-cli = { workspace = true, default-features = true }
1920
sp-runtime = { workspace = true, default-features = true }
2021
sp-statement-store = { workspace = true, default-features = true }
2122
tracing-subscriber = { workspace = true }
2223

24+
[target.'cfg(target_os = "linux")'.dependencies]
25+
# Jemalloc as global allocator prevents huge benchmark regression for storage-heavy extrinsics.
26+
polkadot-jemalloc-shim = { workspace = true, features = ["jemalloc-allocator"] }
27+
2328
[dev-dependencies]
2429
assert_cmd = { workspace = true }
2530
cumulus-test-runtime = { workspace = true }

0 commit comments

Comments
 (0)