Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add benchmarks to test root call overhead #521

Merged
merged 2 commits into from
Oct 18, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
227 changes: 219 additions & 8 deletions crates/wasmi/benches/benches.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ use criterion::{criterion_group, criterion_main, Bencher, Criterion};
use std::{slice, time::Duration};
use wasmi as v1;
use wasmi::core::Value;
use wasmi_core::{F32, F64};
use wasmi_core::{ValueType, F32, F64};

const WASM_KERNEL: &str =
"benches/wasm/wasm_kernel/target/wasm32-unknown-unknown/release/wasm_kernel.wasm";
Expand Down Expand Up @@ -48,6 +48,14 @@ criterion_group! {
bench_execute_regex_redux,
bench_execute_count_until,
bench_execute_trunc_f2i,
bench_execute_typed_bare_call_0,
bench_execute_typed_bare_call_1,
bench_execute_typed_bare_call_4,
bench_execute_typed_bare_call_16,
bench_execute_bare_call_0,
bench_execute_bare_call_1,
bench_execute_bare_call_4,
bench_execute_bare_call_16,
bench_execute_global_bump,
bench_execute_fac_recursive,
bench_execute_fac_opt,
Expand Down Expand Up @@ -273,6 +281,211 @@ fn bench_execute_trunc_f2i(c: &mut Criterion) {
});
}

fn bench_execute_typed_bare_call_0(c: &mut Criterion) {
const REPETITIONS: usize = 20_000;
c.bench_function("execute/bare_call_0/typed", |b| {
let (mut store, instance) = load_instance_from_wat(include_bytes!("wat/bare_call.wat"));
let bare_call = instance
.get_export(&store, "bare_call_0")
.and_then(v1::Extern::into_func)
.unwrap();
let bare_call = bare_call.typed::<(), ()>(&store).unwrap();
b.iter(|| {
for _ in 0..REPETITIONS {
bare_call.call(&mut store, ()).unwrap();
}
})
});
}

fn bench_execute_typed_bare_call_1(c: &mut Criterion) {
const REPETITIONS: usize = 20_000;
c.bench_function("execute/bare_call_1/typed", |b| {
let (mut store, instance) = load_instance_from_wat(include_bytes!("wat/bare_call.wat"));
let bare_call = instance
.get_export(&store, "bare_call_1")
.and_then(v1::Extern::into_func)
.unwrap();
let bare_call = bare_call.typed::<i32, i32>(&store).unwrap();
b.iter(|| {
for _ in 0..REPETITIONS {
let _ = bare_call.call(&mut store, 0).unwrap();
}
})
});
}

fn bench_execute_typed_bare_call_4(c: &mut Criterion) {
const REPETITIONS: usize = 20_000;
type InOut = (i32, i64, F32, F64);
c.bench_function("execute/bare_call_4/typed", |b| {
let (mut store, instance) = load_instance_from_wat(include_bytes!("wat/bare_call.wat"));
let bare_call = instance
.get_export(&store, "bare_call_4")
.and_then(v1::Extern::into_func)
.unwrap();
let bare_call = bare_call.typed::<InOut, InOut>(&store).unwrap();
b.iter(|| {
for _ in 0..REPETITIONS {
let _ = bare_call
.call(&mut store, (0, 0, F32::from(0.0), F64::from(0.0)))
.unwrap();
}
})
});
}

fn bench_execute_typed_bare_call_16(c: &mut Criterion) {
const REPETITIONS: usize = 20_000;
type InOut = (
i32,
i64,
F32,
F64,
i32,
i64,
F32,
F64,
i32,
i64,
F32,
F64,
i32,
i64,
F32,
F64,
);
c.bench_function("execute/bare_call_16/typed", |b| {
let (mut store, instance) = load_instance_from_wat(include_bytes!("wat/bare_call.wat"));
let bare_call = instance
.get_export(&store, "bare_call_16")
.and_then(v1::Extern::into_func)
.unwrap();
let bare_call = bare_call.typed::<InOut, InOut>(&store).unwrap();
b.iter(|| {
for _ in 0..REPETITIONS {
let _ = bare_call
.call(
&mut store,
(
0,
0,
F32::from(0.0),
F64::from(0.0),
0,
0,
F32::from(0.0),
F64::from(0.0),
0,
0,
F32::from(0.0),
F64::from(0.0),
0,
0,
F32::from(0.0),
F64::from(0.0),
),
)
.unwrap();
}
})
});
}

fn bench_execute_bare_call_0(c: &mut Criterion) {
const REPETITIONS: usize = 20_000;
c.bench_function("execute/bare_call_0", |b| {
let (mut store, instance) = load_instance_from_wat(include_bytes!("wat/bare_call.wat"));
let bare_call = instance
.get_export(&store, "bare_call_0")
.and_then(v1::Extern::into_func)
.unwrap();
let params = &[];
let results = &mut [];
b.iter(|| {
for _ in 0..REPETITIONS {
bare_call.call(&mut store, params, results).unwrap();
}
})
});
}

fn bench_execute_bare_call_1(c: &mut Criterion) {
const REPETITIONS: usize = 20_000;
c.bench_function("execute/bare_call_1", |b| {
let (mut store, instance) = load_instance_from_wat(include_bytes!("wat/bare_call.wat"));
let bare_call = instance
.get_export(&store, "bare_call_1")
.and_then(v1::Extern::into_func)
.unwrap();
let params = &[Value::I32(0)];
let results = &mut [Value::I32(0)];
b.iter(|| {
for _ in 0..REPETITIONS {
bare_call.call(&mut store, params, results).unwrap();
}
})
});
}

fn bench_execute_bare_call_4(c: &mut Criterion) {
const REPETITIONS: usize = 20_000;
c.bench_function("execute/bare_call_4", |b| {
let (mut store, instance) = load_instance_from_wat(include_bytes!("wat/bare_call.wat"));
let bare_call = instance
.get_export(&store, "bare_call_4")
.and_then(v1::Extern::into_func)
.unwrap();
let params = &[
Value::default(ValueType::I32),
Value::default(ValueType::I64),
Value::default(ValueType::F32),
Value::default(ValueType::F64),
];
let results = &mut [Value::I32(0); 4];
b.iter(|| {
for _ in 0..REPETITIONS {
bare_call.call(&mut store, params, results).unwrap();
}
})
});
}

fn bench_execute_bare_call_16(c: &mut Criterion) {
const REPETITIONS: usize = 20_000;
c.bench_function("execute/bare_call_16", |b| {
let (mut store, instance) = load_instance_from_wat(include_bytes!("wat/bare_call.wat"));
let bare_call = instance
.get_export(&store, "bare_call_16")
.and_then(v1::Extern::into_func)
.unwrap();
let params = &[
Value::default(ValueType::I32),
Value::default(ValueType::I64),
Value::default(ValueType::F32),
Value::default(ValueType::F64),
Value::default(ValueType::I32),
Value::default(ValueType::I64),
Value::default(ValueType::F32),
Value::default(ValueType::F64),
Value::default(ValueType::I32),
Value::default(ValueType::I64),
Value::default(ValueType::F32),
Value::default(ValueType::F64),
Value::default(ValueType::I32),
Value::default(ValueType::I64),
Value::default(ValueType::F32),
Value::default(ValueType::F64),
];
let results = &mut [Value::I32(0); 16];
b.iter(|| {
for _ in 0..REPETITIONS {
bare_call.call(&mut store, params, results).unwrap();
}
})
});
}

fn bench_execute_global_bump(c: &mut Criterion) {
const BUMP_AMOUNT: i32 = 100_000;
c.bench_function("execute/global_bump", |b| {
Expand Down Expand Up @@ -326,9 +539,8 @@ fn bench_execute_fac_opt(c: &mut Criterion) {
});
}

const RECURSIVE_DEPTH: i32 = 8000;

fn bench_execute_recursive_ok(c: &mut Criterion) {
const RECURSIVE_DEPTH: i32 = 8000;
c.bench_function("execute/recursive_ok", |b| {
let (mut store, instance) = load_instance_from_wat(include_bytes!("wat/recursive_ok.wat"));
let bench_call = instance
Expand All @@ -346,11 +558,10 @@ fn bench_execute_recursive_ok(c: &mut Criterion) {
});
}

const RECURSIVE_SCAN_DEPTH: i32 = 8000;
const RECURSIVE_SCAN_EXPECTED: i32 =
((RECURSIVE_SCAN_DEPTH * RECURSIVE_SCAN_DEPTH) + RECURSIVE_SCAN_DEPTH) / 2;

fn bench_execute_recursive_scan(c: &mut Criterion) {
const RECURSIVE_SCAN_DEPTH: i32 = 8000;
const RECURSIVE_SCAN_EXPECTED: i32 =
((RECURSIVE_SCAN_DEPTH * RECURSIVE_SCAN_DEPTH) + RECURSIVE_SCAN_DEPTH) / 2;
c.bench_function("execute/recursive_scan", |b| {
let (mut store, instance) =
load_instance_from_wat(include_bytes!("wat/recursive_scan.wat"));
Expand All @@ -362,7 +573,7 @@ fn bench_execute_recursive_scan(c: &mut Criterion) {

b.iter(|| {
bench_call
.call(&mut store, &[Value::I32(RECURSIVE_DEPTH)], &mut result)
.call(&mut store, &[Value::I32(RECURSIVE_SCAN_DEPTH)], &mut result)
.unwrap();
assert_eq!(result, [Value::I32(RECURSIVE_SCAN_EXPECTED)]);
})
Expand Down
30 changes: 30 additions & 0 deletions crates/wasmi/benches/wat/bare_call.wat
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
(module
(func (export "bare_call_0") (param) (result))
(func (export "bare_call_1") (param i32) (result i32) local.get 0)
(func (export "bare_call_4") (param i32 i64 f32 f64) (result i32 i64 f32 f64)
local.get 0
local.get 1
local.get 2
local.get 3
)
(func (export "bare_call_16")
(param i32 i64 f32 f64 i32 i64 f32 f64 i32 i64 f32 f64 i32 i64 f32 f64)
(result i32 i64 f32 f64 i32 i64 f32 f64 i32 i64 f32 f64 i32 i64 f32 f64)
local.get 0
local.get 1
local.get 2
local.get 3
local.get 4
local.get 5
local.get 6
local.get 7
local.get 8
local.get 9
local.get 10
local.get 11
local.get 12
local.get 13
local.get 14
local.get 15
)
)