Skip to content

Commit 6bdd0bf

Browse files
committed
Don't clone params on measured hotpath
Signed-off-by: Ludvig Liljenberg <4257730+ludfjig@users.noreply.github.com>
1 parent d95784d commit 6bdd0bf

1 file changed

Lines changed: 9 additions & 7 deletions

File tree

src/hyperlight_host/benches/benchmarks.rs

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -377,11 +377,10 @@ fn guest_call_benchmark_large_param(c: &mut Criterion) {
377377
#[cfg(target_os = "windows")]
378378
group.sample_size(10); // This benchmark is very slow on Windows, so we reduce the sample size to avoid long test runs.
379379

380-
// This benchmark includes time to first clone a vector and string, so it is not a "pure' benchmark of the guest call, but it's still useful
381380
group.bench_function("guest_call_with_large_parameters", |b| {
382381
const SIZE: usize = 50 * 1024 * 1024; // 50 MB
383382
let large_vec = vec![0u8; SIZE];
384-
let large_string = unsafe { String::from_utf8_unchecked(large_vec.clone()) }; // Safety: indeed above vec is valid utf8
383+
let large_string = String::from_utf8(large_vec.clone()).unwrap();
385384

386385
let mut config = SandboxConfiguration::default();
387386
config.set_input_data_size(2 * SIZE + (1024 * 1024)); // 2 * SIZE + 1 MB, to allow 1MB for the rest of the serialized function call
@@ -394,11 +393,14 @@ fn guest_call_benchmark_large_param(c: &mut Criterion) {
394393
.unwrap();
395394
let mut sandbox = sandbox.evolve().unwrap();
396395

397-
b.iter(|| {
398-
sandbox
399-
.call::<()>("LargeParameters", (large_vec.clone(), large_string.clone()))
400-
.unwrap()
401-
});
396+
b.iter_with_setup(
397+
|| (large_vec.clone(), large_string.clone()),
398+
|(vec_clone, string_clone)| {
399+
sandbox
400+
.call::<()>("LargeParameters", (vec_clone, string_clone))
401+
.unwrap()
402+
},
403+
);
402404
});
403405

404406
group.finish();

0 commit comments

Comments
 (0)