@@ -551,6 +551,103 @@ fn shared_memory_benchmark(c: &mut Criterion) {
551551 group. finish ( ) ;
552552}
553553
554+ // ============================================================================
555+ // Benchmark Category: Snapshot Files
556+ // ============================================================================
557+
558+ fn snapshot_file_benchmark ( c : & mut Criterion ) {
559+ use hyperlight_host:: HostFunctions ;
560+ use hyperlight_host:: sandbox:: snapshot:: Snapshot ;
561+
562+ let mut group = c. benchmark_group ( "snapshot_files" ) ;
563+
564+ // Pre-create snapshot files for all sizes
565+ let dirs: Vec < _ > = SandboxSize :: all ( )
566+ . iter ( )
567+ . map ( |size| {
568+ let dir = tempfile:: tempdir ( ) . unwrap ( ) ;
569+ let snap_path = dir. path ( ) . join ( format ! ( "{}.hls" , size. name( ) ) ) ;
570+ let snapshot = {
571+ let mut sbox = create_multiuse_sandbox_with_size ( * size) ;
572+ sbox. snapshot ( ) . unwrap ( )
573+ } ;
574+ snapshot. to_file ( & snap_path) . unwrap ( ) ;
575+ ( dir, snapshot)
576+ } )
577+ . collect ( ) ;
578+
579+ // Benchmark: save_snapshot
580+ for ( i, size) in SandboxSize :: all ( ) . iter ( ) . enumerate ( ) {
581+ let snap_dir = tempfile:: tempdir ( ) . unwrap ( ) ;
582+ let path = snap_dir. path ( ) . join ( "bench.hls" ) ;
583+ let snapshot = & dirs[ i] . 1 ;
584+ group. bench_function ( format ! ( "save_snapshot/{}" , size. name( ) ) , |b| {
585+ b. iter ( || {
586+ snapshot. to_file ( & path) . unwrap ( ) ;
587+ } ) ;
588+ } ) ;
589+ }
590+
591+ // Benchmark: load_snapshot (mmap + header parse + hash verify)
592+ for ( i, size) in SandboxSize :: all ( ) . iter ( ) . enumerate ( ) {
593+ let snap_path = dirs[ i] . 0 . path ( ) . join ( format ! ( "{}.hls" , size. name( ) ) ) ;
594+ group. bench_function ( format ! ( "load_snapshot/{}" , size. name( ) ) , |b| {
595+ b. iter ( || {
596+ let _ = Snapshot :: from_file ( & snap_path) . unwrap ( ) ;
597+ } ) ;
598+ } ) ;
599+ }
600+
601+ // Benchmark: cold_start_via_evolve (new + evolve + call)
602+ for size in SandboxSize :: all ( ) {
603+ group. bench_function ( format ! ( "cold_start_via_evolve/{}" , size. name( ) ) , |b| {
604+ b. iter ( || {
605+ let mut sbox = create_multiuse_sandbox_with_size ( size) ;
606+ sbox. call :: < String > ( "Echo" , "hello\n " . to_string ( ) ) . unwrap ( ) ;
607+ } ) ;
608+ } ) ;
609+ }
610+
611+ // Benchmark: cold_start_via_snapshot (load + from_snapshot + call)
612+ for ( i, size) in SandboxSize :: all ( ) . iter ( ) . enumerate ( ) {
613+ let snap_path = dirs[ i] . 0 . path ( ) . join ( format ! ( "{}.hls" , size. name( ) ) ) ;
614+ group. bench_function ( format ! ( "cold_start_via_snapshot/{}" , size. name( ) ) , |b| {
615+ b. iter ( || {
616+ let loaded = Snapshot :: from_file ( & snap_path) . unwrap ( ) ;
617+ let mut sbox = MultiUseSandbox :: from_snapshot (
618+ std:: sync:: Arc :: new ( loaded) ,
619+ HostFunctions :: default ( ) ,
620+ None ,
621+ )
622+ . unwrap ( ) ;
623+ sbox. call :: < String > ( "Echo" , "hello\n " . to_string ( ) ) . unwrap ( ) ;
624+ } ) ;
625+ } ) ;
626+ }
627+
628+ // Benchmark: cold_start_via_snapshot_unchecked (no hash verify)
629+ for ( i, size) in SandboxSize :: all ( ) . iter ( ) . enumerate ( ) {
630+ let snap_path = dirs[ i] . 0 . path ( ) . join ( format ! ( "{}.hls" , size. name( ) ) ) ;
631+ group. bench_function (
632+ format ! ( "cold_start_via_snapshot_unchecked/{}" , size. name( ) ) ,
633+ |b| {
634+ b. iter ( || {
635+ let loaded = Snapshot :: from_file_unchecked ( & snap_path) . unwrap ( ) ;
636+ let mut sbox = MultiUseSandbox :: from_snapshot (
637+ std:: sync:: Arc :: new ( loaded) ,
638+ HostFunctions :: default ( ) ,
639+ None ,
640+ )
641+ . unwrap ( ) ;
642+ sbox. call :: < String > ( "Echo" , "hello\n " . to_string ( ) ) . unwrap ( ) ;
643+ } ) ;
644+ } ,
645+ ) ;
646+ }
647+
648+ group. finish ( ) ;
649+ }
650+
554651criterion_group ! {
555652 name = benches;
556653 config = Criterion :: default ( ) ;
@@ -561,6 +658,7 @@ criterion_group! {
561658 guest_call_benchmark_large_param,
562659 function_call_serialization_benchmark,
563660 sample_workloads_benchmark,
564- shared_memory_benchmark
661+ shared_memory_benchmark,
662+ snapshot_file_benchmark
565663}
566664criterion_main ! ( benches) ;
0 commit comments