diff --git a/Cargo.lock b/Cargo.lock index 17271accd8341..8be264efee579 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -6847,6 +6847,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 5d9cf766b3286..d84829a5a6a5e 100644 --- a/substrate/utils/frame/omni-bencher/Cargo.toml +++ b/substrate/utils/frame/omni-bencher/Cargo.toml @@ -15,11 +15,16 @@ workspace = true clap = { features = ["derive"], workspace = true } cumulus-primitives-proof-size-hostfunction = { workspace = true, default-features = true } frame-benchmarking-cli = { workspace = true } +polkadot-jemalloc-shim = { workspace = true } sc-cli = { workspace = true, default-features = true } sp-runtime = { workspace = true, default-features = true } sp-statement-store = { workspace = true, default-features = 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 }