Optimize codegen slightly calling wasm functions

Currently wasm-calls work with `Result<T, Trap>` internally but `Trap`
is an enum defined in `wasmtime-runtime` which is actually quite large.
Since traps are supposed to be rare this commit changes these functions
to return a `Box<Trap>` which is un-boxed later up in the `wasmtime`
crate within a `#[cold]` function.
This commit is contained in:
Alex Crichton
2021-08-31 08:34:31 -07:00
parent 25755ff23a
commit c8f55ed688
7 changed files with 38 additions and 27 deletions

View File

@@ -87,7 +87,7 @@ impl Engine {
/// latency of WebAssembly calls are extra-important, which is not
/// necessarily true of all embeddings.
pub fn tls_eager_initialize() -> Result<(), Trap> {
wasmtime_runtime::tls_eager_initialize().map_err(Trap::from_runtime)
wasmtime_runtime::tls_eager_initialize().map_err(Trap::from_runtime_box)
}
/// Returns the configuration settings that this engine is using.

View File

@@ -1056,7 +1056,7 @@ pub(crate) fn invoke_wasm_and_catch_traps<T>(
);
exit_wasm(store, exit);
store.0.entering_native_hook()?;
result.map_err(Trap::from_runtime)
result.map_err(Trap::from_runtime_box)
}
}

View File

@@ -161,6 +161,11 @@ impl Trap {
)
}
#[cold] // see Trap::new
pub(crate) fn from_runtime_box(runtime_trap: Box<wasmtime_runtime::Trap>) -> Self {
Self::from_runtime(*runtime_trap)
}
#[cold] // see Trap::new
pub(crate) fn from_runtime(runtime_trap: wasmtime_runtime::Trap) -> Self {
match runtime_trap {