Skip to content

Commit 36551ea

Browse files
committed
Add combined benchmarks
1 parent 2de6032 commit 36551ea

File tree

1 file changed

+104
-1
lines changed

1 file changed

+104
-1
lines changed

packages/vm/benches/main.rs

Lines changed: 104 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -353,6 +353,102 @@ fn bench_instance_threads(c: &mut Criterion) {
353353
});
354354
}
355355

356+
fn bench_combined(c: &mut Criterion) {
357+
let mut group = c.benchmark_group("Combined");
358+
359+
let options = CacheOptions::new(
360+
TempDir::new().unwrap().into_path(),
361+
capabilities_from_csv("cosmwasm_1_1,cosmwasm_1_2,cosmwasm_1_3,iterator,staking"),
362+
MEMORY_CACHE_SIZE,
363+
DEFAULT_MEMORY_LIMIT,
364+
);
365+
366+
// Store contracts for all benchmarks in this group
367+
let checksum: Checksum = {
368+
let cache: Cache<MockApi, MockStorage, MockQuerier> =
369+
unsafe { Cache::new(options.clone()).unwrap() };
370+
cache.save_wasm(CYBERPUNK).unwrap()
371+
};
372+
373+
group.bench_function("get instance from fs cache and execute", |b| {
374+
let mut non_memcache = options.clone();
375+
non_memcache.memory_cache_size = Size::kibi(0);
376+
377+
let cache: Cache<MockApi, MockStorage, MockQuerier> =
378+
unsafe { Cache::new(non_memcache).unwrap() };
379+
380+
b.iter(|| {
381+
let mut instance = cache
382+
.get_instance(&checksum, mock_backend(&[]), DEFAULT_INSTANCE_OPTIONS)
383+
.unwrap();
384+
assert_eq!(cache.stats().hits_pinned_memory_cache, 0);
385+
assert_eq!(cache.stats().hits_memory_cache, 0);
386+
assert!(cache.stats().hits_fs_cache >= 1);
387+
assert_eq!(cache.stats().misses, 0);
388+
389+
let info = mock_info("guest", &[]);
390+
let msg = br#"{"noop":{}}"#;
391+
let contract_result =
392+
call_execute::<_, _, _, Empty>(&mut instance, &mock_env(), &info, msg).unwrap();
393+
contract_result.into_result().unwrap();
394+
});
395+
});
396+
397+
group.bench_function("get instance from memory cache and execute", |b| {
398+
let cache: Cache<MockApi, MockStorage, MockQuerier> =
399+
unsafe { Cache::new(options.clone()).unwrap() };
400+
401+
// Load into memory
402+
cache
403+
.get_instance(&checksum, mock_backend(&[]), DEFAULT_INSTANCE_OPTIONS)
404+
.unwrap();
405+
406+
b.iter(|| {
407+
let backend = mock_backend(&[]);
408+
let mut instance = cache
409+
.get_instance(&checksum, backend, DEFAULT_INSTANCE_OPTIONS)
410+
.unwrap();
411+
assert_eq!(cache.stats().hits_pinned_memory_cache, 0);
412+
assert!(cache.stats().hits_memory_cache >= 1);
413+
assert_eq!(cache.stats().hits_fs_cache, 1);
414+
assert_eq!(cache.stats().misses, 0);
415+
416+
let info = mock_info("guest", &[]);
417+
let msg = br#"{"noop":{}}"#;
418+
let contract_result =
419+
call_execute::<_, _, _, Empty>(&mut instance, &mock_env(), &info, msg).unwrap();
420+
contract_result.into_result().unwrap();
421+
});
422+
});
423+
424+
group.bench_function("get instance from pinned memory and execute", |b| {
425+
let cache: Cache<MockApi, MockStorage, MockQuerier> =
426+
unsafe { Cache::new(options.clone()).unwrap() };
427+
428+
// Load into pinned memory
429+
cache.pin(&checksum).unwrap();
430+
431+
b.iter(|| {
432+
let backend = mock_backend(&[]);
433+
let mut instance = cache
434+
.get_instance(&checksum, backend, DEFAULT_INSTANCE_OPTIONS)
435+
.unwrap();
436+
assert_eq!(cache.stats().hits_memory_cache, 0);
437+
assert!(cache.stats().hits_pinned_memory_cache >= 1);
438+
assert_eq!(cache.stats().hits_fs_cache, 1);
439+
assert_eq!(cache.stats().misses, 0);
440+
441+
let info = mock_info("guest", &[]);
442+
let msg = br#"{"noop":{}}"#;
443+
let contract_result =
444+
call_execute::<_, _, _, Empty>(&mut instance, &mock_env(), &info, msg).unwrap();
445+
contract_result.into_result().unwrap();
446+
});
447+
});
448+
449+
group.finish();
450+
}
451+
356452
fn make_config(measurement_time_s: u64) -> Criterion {
357453
Criterion::default()
358454
.without_plots()
@@ -371,6 +467,13 @@ criterion_group!(
371467
config = make_config(8);
372468
targets = bench_cache
373469
);
470+
// Combines loading module from cache, instantiating it and executing the instance.
471+
// This is what every call in libwasmvm does.
472+
criterion_group!(
473+
name = combined;
474+
config = make_config(5);
475+
targets = bench_combined
476+
);
374477
criterion_group!(
375478
name = multi_threaded_instance;
376479
config = Criterion::default()
@@ -380,4 +483,4 @@ criterion_group!(
380483
.configure_from_args();
381484
targets = bench_instance_threads
382485
);
383-
criterion_main!(instance, cache, multi_threaded_instance);
486+
criterion_main!(instance, cache, combined, multi_threaded_instance);

0 commit comments

Comments
 (0)