Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: bypass serialized cache in wasmer_wamr flag #119

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading