@@ -19,8 +19,6 @@ use hyperlight_host::GuestBinary;
1919use hyperlight_host:: sandbox:: {
2020 Callable , MultiUseSandbox , SandboxConfiguration , UninitializedSandbox ,
2121} ;
22- use hyperlight_host:: sandbox_state:: sandbox:: EvolvableSandbox ;
23- use hyperlight_host:: sandbox_state:: transition:: Noop ;
2422use hyperlight_testing:: simple_guest_as_string;
2523
2624fn create_uninit_sandbox ( ) -> UninitializedSandbox {
@@ -29,7 +27,7 @@ fn create_uninit_sandbox() -> UninitializedSandbox {
2927}
3028
3129fn create_multiuse_sandbox ( ) -> MultiUseSandbox {
32- create_uninit_sandbox ( ) . evolve ( Noop :: default ( ) ) . unwrap ( )
30+ create_uninit_sandbox ( ) . evolve ( ) . unwrap ( )
3331}
3432
3533fn guest_call_benchmark ( c : & mut Criterion ) {
@@ -38,24 +36,20 @@ fn guest_call_benchmark(c: &mut Criterion) {
3836 // Benchmarks a single guest function call.
3937 // The benchmark does **not** include the time to reset the sandbox memory after the call.
4038 group. bench_function ( "guest_call" , |b| {
41- let mut call_ctx = create_multiuse_sandbox ( ) . new_call_context ( ) ;
39+ let mut sbox = create_multiuse_sandbox ( ) ;
4240
43- b. iter ( || {
44- call_ctx
45- . call :: < String > ( "Echo" , "hello\n " . to_string ( ) )
46- . unwrap ( )
47- } ) ;
41+ b. iter ( || sbox. call :: < String > ( "Echo" , "hello\n " . to_string ( ) ) . unwrap ( ) ) ;
4842 } ) ;
4943
5044 // Benchmarks a single guest function call.
5145 // The benchmark does include the time to reset the sandbox memory after the call.
52- group. bench_function ( "guest_call_with_reset" , |b| {
53- let mut sandbox = create_multiuse_sandbox ( ) ;
46+ group. bench_function ( "guest_call_with_restore" , |b| {
47+ let mut sbox = create_multiuse_sandbox ( ) ;
48+ let snapshot = sbox. snapshot ( ) . unwrap ( ) ;
5449
5550 b. iter ( || {
56- sandbox
57- . call_guest_function_by_name :: < String > ( "Echo" , "hello\n " . to_string ( ) )
58- . unwrap ( )
51+ sbox. call :: < String > ( "Echo" , "hello\n " . to_string ( ) ) . unwrap ( ) ;
52+ sbox. restore ( & snapshot) . unwrap ( ) ;
5953 } ) ;
6054 } ) ;
6155
@@ -69,11 +63,13 @@ fn guest_call_benchmark(c: &mut Criterion) {
6963 . register ( "HostAdd" , |a : i32 , b : i32 | Ok ( a + b) )
7064 . unwrap ( ) ;
7165
72- let multiuse_sandbox: MultiUseSandbox =
73- uninitialized_sandbox. evolve ( Noop :: default ( ) ) . unwrap ( ) ;
74- let mut call_ctx = multiuse_sandbox. new_call_context ( ) ;
66+ let mut multiuse_sandbox: MultiUseSandbox = uninitialized_sandbox. evolve ( ) . unwrap ( ) ;
7567
76- b. iter ( || call_ctx. call :: < i32 > ( "Add" , ( 1_i32 , 41_i32 ) ) . unwrap ( ) ) ;
68+ b. iter ( || {
69+ multiuse_sandbox
70+ . call :: < i32 > ( "Add" , ( 1_i32 , 41_i32 ) )
71+ . unwrap ( )
72+ } ) ;
7773 } ) ;
7874
7975 group. finish ( ) ;
@@ -99,7 +95,7 @@ fn guest_call_benchmark_large_param(c: &mut Criterion) {
9995 Some ( config) ,
10096 )
10197 . unwrap ( ) ;
102- let mut sandbox = sandbox. evolve ( Noop :: default ( ) ) . unwrap ( ) ;
98+ let mut sandbox = sandbox. evolve ( ) . unwrap ( ) ;
10399
104100 b. iter ( || {
105101 sandbox
@@ -139,17 +135,6 @@ fn sandbox_benchmark(c: &mut Criterion) {
139135 b. iter ( create_multiuse_sandbox) ;
140136 } ) ;
141137
142- // Benchmarks the time to create a new sandbox and create a new call context.
143- // Does **not** include the time to drop the sandbox or the call context.
144- group. bench_function ( "create_sandbox_and_call_context" , |b| {
145- b. iter_with_large_drop ( || create_multiuse_sandbox ( ) . new_call_context ( ) ) ;
146- } ) ;
147-
148- // Benchmarks the time to create a new sandbox, create a new call context, and drop the call context.
149- group. bench_function ( "create_sandbox_and_call_context_and_drop" , |b| {
150- b. iter ( || create_multiuse_sandbox ( ) . new_call_context ( ) ) ;
151- } ) ;
152-
153138 group. finish ( ) ;
154139}
155140
0 commit comments