Skip to content

Commit

Permalink
refactor: bypass serialized cache in wasmer_wamr flag
Browse files Browse the repository at this point in the history
There is no utility to caching serialized wasms as they are not pre-compiled. Attempting to use a previously pre-compiled wasm in the interpreter engine will fail.
  • Loading branch information
mattyg committed Sep 12, 2024
1 parent 280f3ac commit 764a33d
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions crates/host/src/module/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,7 @@ impl SerializedModuleCache {

/// Given a wasm, compiles with compiler engine, serializes the result, adds it to
/// the cache and returns that.
#[cfg(feature = "wasmer_sys")]
fn get_with_build_cache(
&mut self,
key: CacheKey,
Expand Down Expand Up @@ -293,6 +294,7 @@ impl SerializedModuleCache {

/// Given a wasm, attempts to get the serialized module for it from the cache.
/// If the cache misses, a new serialized module will be built from the wasm.
#[cfg(feature = "wasmer_sys")]
pub fn get(&mut self, key: CacheKey, wasm: &[u8]) -> Result<Arc<Module>, wasmer::RuntimeError> {
match self.cache.get(&key) {
Some(serialized_module) => {
Expand All @@ -306,6 +308,18 @@ impl SerializedModuleCache {
None => self.get_with_build_cache(key, wasm),
}
}

/// Bypass the cache entirely, returning a wasm module.
/// Wasm are intepretered (not compiled) when using the feature `wasmer_wamr`,
/// so there is no utility in caching them in a pre-serialized format.
#[cfg(feature = "wasmer_wamr")]
pub fn get(&mut self, key: CacheKey, wasm: &[u8]) -> Result<Arc<Module>, wasmer::RuntimeError> {
let engine = (self.make_engine)();
let module = Module::from_binary(&engine, wasm)
.map_err(|e| wasm_error!(WasmErrorInner::Compile(e.to_string())))?;

Ok(Arc::new(module))
}
}

/// Caches deserialized wasm modules. Deserialization of cached modules from
Expand Down

0 comments on commit 764a33d

Please sign in to comment.