diff --git a/Cargo.lock b/Cargo.lock index d3fb2e54f9669..5f6c939fdf483 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -6983,6 +6983,7 @@ dependencies = [ "cumulus-primitives-proof-size-hostfunction", "cumulus-test-runtime", "frame-benchmarking-cli", + "polkadot-jemalloc-shim", "sc-chain-spec", "sc-cli", "sp-genesis-builder", diff --git a/prdoc/pr_11069.prdoc b/prdoc/pr_11069.prdoc new file mode 100644 index 0000000000000..1e32bcd839bda --- /dev/null +++ b/prdoc/pr_11069.prdoc @@ -0,0 +1,11 @@ +title: 'frame-omni-bencher: enable jemalloc-allocator' +doc: +- audience: Runtime Dev + description: |- + 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. + Revert also the dummy write/read workaround at the end of commit_db() introduced by #10947. +crates: +- name: frame-omni-bencher + bump: patch +- name: frame-benchmarking + bump: patch diff --git a/substrate/frame/benchmarking/src/utils.rs b/substrate/frame/benchmarking/src/utils.rs index c081bc7af682c..acd2f0401302a 100644 --- a/substrate/frame/benchmarking/src/utils.rs +++ b/substrate/frame/benchmarking/src/utils.rs @@ -290,19 +290,6 @@ pub trait Benchmarking { /// Commit pending storage changes to the trie database and clear the database cache. fn commit_db(&mut self) { self.commit(); - - // Warmup the memory allocator after bulk deallocation. - // After draining the overlay with many entries, the first new allocation can trigger memory - // defragmentation. The warmup key is whitelisted so these operations don't appear in - // benchmark results. - const WARMUP_KEY: &[u8] = b":benchmark_warmup:"; - let mut whitelist = self.get_whitelist(); - if !whitelist.iter().any(|k| k.key == WARMUP_KEY) { - whitelist.push(WARMUP_KEY.to_vec().into()); - self.set_whitelist(whitelist); - } - self.place_storage(WARMUP_KEY.to_vec(), Some(vec![0u8; 32])); - self.place_storage(WARMUP_KEY.to_vec(), None); } /// Get the read/write count. diff --git a/substrate/utils/frame/omni-bencher/Cargo.toml b/substrate/utils/frame/omni-bencher/Cargo.toml index aba7ed3e00adf..9f541a5d8fd9b 100644 --- a/substrate/utils/frame/omni-bencher/Cargo.toml +++ b/substrate/utils/frame/omni-bencher/Cargo.toml @@ -16,6 +16,7 @@ clap = { features = ["derive"], workspace = true } cumulus-primitives-proof-size-hostfunction.default-features = true cumulus-primitives-proof-size-hostfunction.workspace = true frame-benchmarking-cli.workspace = true +polkadot-jemalloc-shim.workspace = true sc-cli.default-features = true sc-cli.workspace = true sp-runtime.default-features = true @@ -24,6 +25,10 @@ sp-statement-store.default-features = true sp-statement-store.workspace = true tracing-subscriber = { workspace = true } +[target.'cfg(target_os = "linux")'.dependencies] +# Jemalloc as global allocator prevents huge benchmark regression for storage-heavy extrinsics. +polkadot-jemalloc-shim = { workspace = true, features = ["jemalloc-allocator"] } + [dev-dependencies] assert_cmd = { workspace = true } cumulus-test-runtime = { workspace = true }