Skip to content
Merged
Show file tree
Hide file tree
Changes from 5 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
9 changes: 9 additions & 0 deletions prdoc/pr_10947.prdoc
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
title: 'benchmarking: fix DB read/write counts'
doc:
- audience: Runtime Dev
description: |-
PR #10802 added `reset_read_write_count()` at the end of commit_db() to prevent warmup operations from appearing in benchmarking results. However, commit_db is called twice: one on `on_before_start()` closure before benchmark, and one after benchmark execution after benchmark.
This PR whitelists warmup key so that it doesn't appear in the read/write count.
crates:
- name: frame-benchmarking
bump: patch
11 changes: 7 additions & 4 deletions substrate/frame/benchmarking/src/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -293,13 +293,16 @@ pub trait Benchmarking {

// Warmup the memory allocator after bulk deallocation.
// After draining the overlay with many entries, the first new allocation can trigger memory
// defragmentation.
// 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);

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

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