Skip to content

Commit b51c19f

Browse files
committed
Add snapshot file benchmarks
Signed-off-by: Ludvig Liljenberg <4257730+ludfjig@users.noreply.github.com>
1 parent 370b115 commit b51c19f

1 file changed

Lines changed: 97 additions & 1 deletion

File tree

src/hyperlight_host/benches/benchmarks.rs

Lines changed: 97 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -551,6 +551,101 @@ 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+
)
621+
.unwrap();
622+
sbox.call::<String>("Echo", "hello\n".to_string()).unwrap();
623+
});
624+
});
625+
}
626+
627+
// Benchmark: cold_start_via_snapshot_unchecked (no hash verify)
628+
for (i, size) in SandboxSize::all().iter().enumerate() {
629+
let snap_path = dirs[i].0.path().join(format!("{}.hls", size.name()));
630+
group.bench_function(
631+
format!("cold_start_via_snapshot_unchecked/{}", size.name()),
632+
|b| {
633+
b.iter(|| {
634+
let loaded = Snapshot::from_file_unchecked(&snap_path).unwrap();
635+
let mut sbox = MultiUseSandbox::from_snapshot(
636+
std::sync::Arc::new(loaded),
637+
HostFunctions::default(),
638+
)
639+
.unwrap();
640+
sbox.call::<String>("Echo", "hello\n".to_string()).unwrap();
641+
});
642+
},
643+
);
644+
}
645+
646+
group.finish();
647+
}
648+
554649
criterion_group! {
555650
name = benches;
556651
config = Criterion::default();
@@ -561,6 +656,7 @@ criterion_group! {
561656
guest_call_benchmark_large_param,
562657
function_call_serialization_benchmark,
563658
sample_workloads_benchmark,
564-
shared_memory_benchmark
659+
shared_memory_benchmark,
660+
snapshot_file_benchmark
565661
}
566662
criterion_main!(benches);

0 commit comments

Comments
 (0)