@@ -379,11 +379,10 @@ fn guest_call_benchmark_large_param(c: &mut Criterion) {
379379 #[ cfg( target_os = "windows" ) ]
380380 group. sample_size ( 10 ) ; // This benchmark is very slow on Windows, so we reduce the sample size to avoid long test runs.
381381
382- // 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
383382 group. bench_function ( "guest_call_with_large_parameters" , |b| {
384383 const SIZE : usize = 50 * 1024 * 1024 ; // 50 MB
385384 let large_vec = vec ! [ 0u8 ; SIZE ] ;
386- let large_string = unsafe { String :: from_utf8_unchecked ( large_vec. clone ( ) ) } ; // Safety: indeed above vec is valid utf8
385+ let large_string = String :: from_utf8 ( large_vec. clone ( ) ) . unwrap ( ) ;
387386
388387 let mut config = SandboxConfiguration :: default ( ) ;
389388 config. set_input_data_size ( 2 * SIZE + ( 1024 * 1024 ) ) ; // 2 * SIZE + 1 MB, to allow 1MB for the rest of the serialized function call
@@ -397,11 +396,14 @@ fn guest_call_benchmark_large_param(c: &mut Criterion) {
397396 . unwrap ( ) ;
398397 let mut sandbox = sandbox. evolve ( ) . unwrap ( ) ;
399398
400- b. iter ( || {
401- sandbox
402- . call :: < ( ) > ( "LargeParameters" , ( large_vec. clone ( ) , large_string. clone ( ) ) )
403- . unwrap ( ) ;
404- } ) ;
399+ b. iter_with_setup (
400+ || ( large_vec. clone ( ) , large_string. clone ( ) ) ,
401+ |( vec_clone, string_clone) | {
402+ sandbox
403+ . call :: < ( ) > ( "LargeParameters" , ( vec_clone, string_clone) )
404+ . unwrap ( )
405+ } ,
406+ ) ;
405407 } ) ;
406408
407409 group. finish ( ) ;
0 commit comments