Skip to content

Commit

Permalink
Add the ability to cache typechecking an instance (#2962)
Browse files Browse the repository at this point in the history
* Add the ability to cache typechecking an instance

This commit adds the abilty to cache the type-checked imports of an
instance if an instance is going to be instantiated multiple times. This
can also be useful to do a "dry run" of instantiation where no wasm code
is run but it's double-checked that a `Linker` possesses everything
necessary to instantiate the provided module.

This should ideally help cut down repeated instantiation costs slightly
by avoiding type-checking and allocation a `Vec<Extern>` on each
instantiation. It's expected though that the impact on instantiation
time is quite small and likely not super significant. The functionality,
though, of pre-checking can be useful for some embeddings.

* Fix build with async
  • Loading branch information
alexcrichton authored Jun 3, 2021
1 parent e25bf36 commit 05baddf
Show file tree
Hide file tree
Showing 8 changed files with 459 additions and 175 deletions.
6 changes: 5 additions & 1 deletion crates/wasmtime/src/func.rs
Original file line number Diff line number Diff line change
Expand Up @@ -677,7 +677,7 @@ impl Func {
/// initiates a panic. Also panics if `store` does not own this function.
pub fn call(&self, mut store: impl AsContextMut, params: &[Val]) -> Result<Box<[Val]>> {
assert!(
!cfg!(feature = "async") || !store.as_context().async_support(),
!store.as_context().async_support(),
"must use `call_async` when async support is enabled on the config",
);
let my_ty = self.ty(&store);
Expand Down Expand Up @@ -1894,6 +1894,10 @@ impl HostFunc {
let idx = self.export.anyfunc.as_ref().type_index;
store.register_host_trampoline(idx, self.trampoline);
}

pub(crate) fn sig_index(&self) -> VMSharedSignatureIndex {
unsafe { self.export.anyfunc.as_ref().type_index }
}
}

impl Drop for HostFunc {
Expand Down
2 changes: 1 addition & 1 deletion crates/wasmtime/src/func/typed.rs
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ where
pub fn call(&self, mut store: impl AsContextMut, params: Params) -> Result<Results, Trap> {
let mut store = store.as_context_mut().opaque();
assert!(
!cfg!(feature = "async") || !store.async_support(),
!store.async_support(),
"must use `call_async` with async stores"
);
unsafe { self._call(&mut store, params) }
Expand Down
Loading

0 comments on commit 05baddf

Please sign in to comment.