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:
@@ -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.
|
||||
|
||||
@@ -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)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -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 {
|
||||
|
||||
Reference in New Issue
Block a user