Skip to content

Commit

Permalink
nit
Browse files Browse the repository at this point in the history
  • Loading branch information
pgherveou committed Apr 2, 2024
1 parent ccac116 commit 24eab39
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 10 deletions.
18 changes: 11 additions & 7 deletions substrate/frame/contracts/src/benchmarking/call_builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ impl<T> LeakReclaimer<T> {
/// reference to its content, along with the guard for later cleanup.
///
/// # Safety
///
/// The caller must ensure that the returned reference is not used after the `LeakReclaimer` is
/// dropped.
unsafe fn new(value: T) -> (&'static mut T, Self) {
Expand Down Expand Up @@ -75,11 +76,11 @@ where
/// Prepare a call to the module.
/// Returns a tuple containing an opaque object that will reclaim the leaked boxes and a closure
/// used to invoke the call.
///
/// Safety: The caller must ensure that the "Leak Guard" is dropped after the call is invoked.
pub unsafe fn build(self) -> (impl Drop, impl FnOnce()) {
pub fn build(self) -> impl FnOnce() {
let input = self.input.clone();
let (sbox, reclaim_sbox) = LeakReclaimer::new(self);

// Safety: reclaim_sbox is dropped after the closure is called.
let (sbox, reclaim_sbox) = unsafe { LeakReclaimer::new(self) };

let (ext, module) = Stack::bench_new_call(
sbox.dest.clone(),
Expand All @@ -92,10 +93,13 @@ where
Determinism::Enforced,
);

let (ext, reclaim_ext): (&mut StackExt<T>, _) = LeakReclaimer::new(ext);
// Safety: reclaim_ext is dropped after the closure is called.
let (ext, reclaim_ext): (&mut StackExt<T>, _) = unsafe { LeakReclaimer::new(ext) };
let (func, mut store) = module.bench_prepare_call(ext, input);
(Box::new((reclaim_ext, reclaim_sbox)), move || {
move || {
func.call(&mut store, &[], &mut []).unwrap();
})
drop(reclaim_ext);
drop(reclaim_sbox);
}
}
}
4 changes: 1 addition & 3 deletions substrate/frame/contracts/src/benchmarking/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -799,13 +799,11 @@ mod benchmarks {

#[benchmark(pov_mode = Measured)]
fn seal_now(r: Linear<0, API_BENCHMARK_RUNS>) {
let builder = CallBuilder::<T>::new(WasmModule::getter("seal0", "seal_now", r));
let (reclaim, invoke) = unsafe { builder.build() };
let invoke = CallBuilder::<T>::new(WasmModule::getter("seal0", "seal_now", r)).build();
#[block]
{
invoke();
}
drop(reclaim);
}

#[benchmark(pov_mode = Measured)]
Expand Down

0 comments on commit 24eab39

Please sign in to comment.