Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions prdoc/pr_10802.prdoc
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
title: 'benchmarking: fix timing leak from bulk setup operations'
doc:
- audience: Runtime Dev
description: |-
Fixes timing leaks in benchmarks with large setup operations (e.g., clearing
27k staking entries). After bulk deletions are committed, the first new allocation
can trigger memory allocator overhead that leaks into benchmark timing.

The fix adds a memory allocator warmup step in `commit_db()` that performs a
dummy write/clear cycle to absorb this overhead before timing starts.
crates:
- name: frame-benchmarking
bump: patch
12 changes: 11 additions & 1 deletion substrate/frame/benchmarking/src/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -289,7 +289,17 @@ pub trait Benchmarking {

/// Commit pending storage changes to the trie database and clear the database cache.
fn commit_db(&mut self) {
self.commit()
self.commit();

// Warmup the memory allocator after bulk deallocation.
// After draining the overlay with many entries, the first new allocation can trigger memory
// defragmentation.
const WARMUP_KEY: &[u8] = b":benchmark_warmup:";
self.place_storage(WARMUP_KEY.to_vec(), Some(vec![0u8; 32]));
self.place_storage(WARMUP_KEY.to_vec(), None);

// Reset tracking so warmup operations don't appear in benchmark results.
self.reset_read_write_count();
}

/// Get the read/write count.
Expand Down
Loading