Merge pull request #3281 from alexcrichton/small-opts

Some small optimizations for calling wasm functions
This commit is contained in:
Nick Fitzgerald
2021-09-02 15:06:42 -07:00
committed by GitHub
9 changed files with 45 additions and 29 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

@@ -368,6 +368,7 @@ macro_rules! impl_wasm_params {
}
}
#[inline]
fn into_abi(self, _store: &mut StoreOpaque) -> Option<Self::Abi> {
let ($($t,)*) = self;
$(
@@ -446,6 +447,7 @@ macro_rules! impl_wasm_results {
{
type ResultAbi = ($($t::Abi,)*);
#[inline]
unsafe fn from_abi(store: &mut StoreOpaque, abi: Self::ResultAbi) -> Self {
let ($($t,)*) = abi;
($($t::from_abi($t, store),)*)

View File

@@ -726,6 +726,7 @@ impl StoreInnermost {
Ok(())
}
#[inline]
pub fn async_support(&self) -> bool {
cfg!(feature = "async") && self.engine().config().async_support
@@ -736,10 +737,12 @@ impl StoreInnermost {
&self.engine
}
#[inline]
pub fn store_data(&self) -> &StoreData {
&self.store_data
}
#[inline]
pub fn store_data_mut(&mut self) -> &mut StoreData {
&mut self.store_data
}
@@ -1230,9 +1233,9 @@ impl AsyncCx {
Poll::Pending => {}
}
let before = wasmtime_runtime::TlsRestore::take().map_err(Trap::from_runtime)?;
let before = wasmtime_runtime::TlsRestore::take().map_err(Trap::from_runtime_box)?;
let res = (*suspend).suspend(());
before.replace().map_err(Trap::from_runtime)?;
before.replace().map_err(Trap::from_runtime_box)?;
res?;
}
}

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 {