Skip to content

Commit 029ae05

Browse files
committed
Whitelist warmup key
1 parent 3f0ddd8 commit 029ae05

File tree

3 files changed

+10
-8
lines changed

3 files changed

+10
-8
lines changed

prdoc/pr_10947.prdoc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ doc:
33
- audience: Runtime Dev
44
description: |-
55
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.
6-
This PR moves read_write_count() call before the post-benchmark commit_db() call.
6+
This PR whitelists the warmup keys so that it doesn't appear in the read/write count.
77
crates:
88
- name: frame-benchmarking
99
bump: patch

substrate/frame/benchmarking/src/utils.rs

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -293,13 +293,16 @@ pub trait Benchmarking {
293293

294294
// Warmup the memory allocator after bulk deallocation.
295295
// After draining the overlay with many entries, the first new allocation can trigger memory
296-
// defragmentation.
296+
// defragmentation. The warmup key is whitelisted so these operations don't appear in
297+
// benchmark results.
297298
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(TrackedStorageKey::from(WARMUP_KEY.to_vec()));
302+
self.set_whitelist(whitelist);
303+
}
298304
self.place_storage(WARMUP_KEY.to_vec(), Some(vec![0u8; 32]));
299305
self.place_storage(WARMUP_KEY.to_vec(), None);
300-
301-
// Reset tracking so warmup operations don't appear in benchmark results.
302-
self.reset_read_write_count();
303306
}
304307

305308
/// Get the read/write count.

substrate/frame/benchmarking/src/v1.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1117,14 +1117,13 @@ macro_rules! impl_benchmark {
11171117
let elapsed_extrinsic = recording.elapsed_extrinsic().expect("elapsed time should be recorded");
11181118
let diff_pov = recording.diff_pov().unwrap_or_default();
11191119

1120-
// Capture read/write count BEFORE commit_db resets the counters
1121-
let read_write_count = $crate::benchmarking::read_write_count();
1122-
// Commit the changes to the database
1120+
// Commit the changes to get proper write count
11231121
$crate::benchmarking::commit_db();
11241122
$crate::__private::log::trace!(
11251123
target: "benchmark",
11261124
"End Benchmark: {} ns", elapsed_extrinsic
11271125
);
1126+
let read_write_count = $crate::benchmarking::read_write_count();
11281127
$crate::__private::log::trace!(
11291128
target: "benchmark",
11301129
"Read/Write Count {:?}", read_write_count

0 commit comments

Comments
 (0)