-
Notifications
You must be signed in to change notification settings - Fork 29
Component benchmarks #93
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
Merged
jsturtevant
merged 1 commit into
hyperlight-dev:main
from
jsturtevant:component-benchmarks
Jul 11, 2025
+231
−21
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,110 @@ | ||
use std::sync::{Arc, Mutex}; | ||
|
||
use criterion::{Bencher, Criterion, criterion_group, criterion_main}; | ||
use hyperlight_wasm::{LoadedWasmSandbox, SandboxBuilder}; | ||
|
||
use crate::bindings::example::runcomponent::Guest; | ||
|
||
extern crate alloc; | ||
mod bindings { | ||
hyperlight_component_macro::host_bindgen!( | ||
"../../src/wasmsamples/components/runcomponent-world.wasm" | ||
); | ||
} | ||
|
||
pub struct State {} | ||
impl State { | ||
pub fn new() -> Self { | ||
State {} | ||
} | ||
} | ||
|
||
impl Default for State { | ||
fn default() -> Self { | ||
Self::new() | ||
} | ||
} | ||
|
||
impl bindings::example::runcomponent::Host for State { | ||
fn r#get_time_since_boot_microsecond(&mut self) -> i64 { | ||
let res = std::time::SystemTime::now() | ||
.duration_since(std::time::SystemTime::UNIX_EPOCH) | ||
.unwrap() | ||
.as_micros(); | ||
i64::try_from(res).unwrap() | ||
} | ||
} | ||
|
||
impl bindings::example::runcomponent::RuncomponentImports for State { | ||
type Host = State; | ||
|
||
fn r#host(&mut self) -> impl ::core::borrow::BorrowMut<Self::Host> { | ||
self | ||
} | ||
} | ||
|
||
fn wasm_component_guest_call_benchmark(c: &mut Criterion) { | ||
let mut group = c.benchmark_group("wasm_component_guest_functions"); | ||
|
||
let bench_guest_function = |b: &mut Bencher<'_>, ext| { | ||
let (sb, rt) = get_loaded_wasm_sandbox(ext); | ||
let mut wrapped = bindings::RuncomponentSandbox { sb, rt }; | ||
let instance = bindings::example::runcomponent::RuncomponentExports::guest(&mut wrapped); | ||
|
||
b.iter(|| { | ||
instance.echo("Hello World!".to_string()); | ||
}); | ||
}; | ||
|
||
group.bench_function("wasm_guest_call", |b: &mut Bencher<'_>| { | ||
bench_guest_function(b, "wasm"); | ||
}); | ||
|
||
group.bench_function("wasm_guest_call_aot", |b: &mut Bencher<'_>| { | ||
bench_guest_function(b, "aot"); | ||
}); | ||
|
||
group.finish(); | ||
} | ||
|
||
fn wasm_component_sandbox_benchmark(c: &mut Criterion) { | ||
let mut group = c.benchmark_group("wasm_component_sandboxes"); | ||
let create_wasm_sandbox = || { | ||
get_loaded_wasm_sandbox("wasm"); | ||
}; | ||
|
||
group.bench_function("create_sandbox", |b| { | ||
b.iter_with_large_drop(create_wasm_sandbox); | ||
}); | ||
|
||
group.bench_function("create_sandbox_and_drop", |b| { | ||
b.iter(create_wasm_sandbox); | ||
}); | ||
|
||
group.finish(); | ||
} | ||
|
||
fn get_loaded_wasm_sandbox( | ||
ext: &str, | ||
) -> ( | ||
LoadedWasmSandbox, | ||
Arc<Mutex<bindings::RuncomponentResources<State>>>, | ||
) { | ||
let state = State::new(); | ||
let mut sandbox = SandboxBuilder::new().build().unwrap(); | ||
let rt = bindings::register_host_functions(&mut sandbox, state); | ||
|
||
let sb = sandbox.load_runtime().unwrap(); | ||
|
||
let sb = sb | ||
.load_module(format!("../../x64/release/runcomponent.{ext}",)) | ||
.unwrap(); | ||
(sb, rt) | ||
} | ||
|
||
criterion_group! { | ||
name = benches_components; | ||
config = Criterion::default();//.warm_up_time(Duration::from_millis(50)); // If warm_up_time is default 3s warmup, the benchmark will fail due memory error | ||
targets = wasm_component_guest_call_benchmark, wasm_component_sandbox_benchmark | ||
} | ||
criterion_main!(benches_components); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
#include "bindings/runcomponent.h" | ||
#include <stdlib.h> | ||
#include <string.h> | ||
|
||
void exports_example_runcomponent_guest_echo(runcomponent_string_t *msg, runcomponent_string_t *ret) | ||
{ | ||
ret->len = msg->len; | ||
ret->ptr = (uint8_t *) malloc(ret->len); | ||
memcpy(ret->ptr, msg->ptr, ret->len); | ||
runcomponent_string_free(msg); | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
package example:runcomponent; | ||
|
||
interface guest { | ||
echo: func(msg: string) -> string; | ||
} | ||
|
||
interface host { | ||
get-time-since-boot-microsecond: func() -> s64; | ||
} | ||
|
||
world runcomponent { | ||
export guest; | ||
import host; | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.