Improved cache mechanism

This commit is contained in:
Syrus
2020-06-11 14:38:08 -07:00
parent bf03c734fc
commit c6b34ecde3
4 changed files with 11 additions and 12 deletions

View File

@@ -20,5 +20,5 @@ pub trait Cache {
unsafe fn load(&self, store: &Store, key: WasmHash) -> Result<Module, Self::DeserializeError>; unsafe fn load(&self, store: &Store, key: WasmHash) -> Result<Module, Self::DeserializeError>;
/// Store a [`Module`] into the cache with the given [`WasmHash`]. /// Store a [`Module`] into the cache with the given [`WasmHash`].
fn store(&mut self, key: WasmHash, module: Module) -> Result<(), Self::SerializeError>; fn store(&mut self, key: WasmHash, module: &Module) -> Result<(), Self::SerializeError>;
} }

View File

@@ -78,7 +78,7 @@ impl Cache for FileSystemCache {
Module::deserialize_from_file(&store, new_path_buf) Module::deserialize_from_file(&store, new_path_buf)
} }
fn store(&mut self, key: WasmHash, module: Module) -> Result<(), Self::SerializeError> { fn store(&mut self, key: WasmHash, module: &Module) -> Result<(), Self::SerializeError> {
let filename = key.to_string(); let filename = key.to_string();
let mut new_path_buf = self.path.clone(); let mut new_path_buf = self.path.clone();

View File

@@ -195,7 +195,7 @@ impl Run {
} }
let module = Module::new(&store, &contents)?; let module = Module::new(&store, &contents)?;
// Store the compiled Module in cache // Store the compiled Module in cache
cache.store(hash, module.clone())?; cache.store(hash, &module)?;
Ok(module) Ok(module)
} }
} }

View File

@@ -2,13 +2,14 @@
//! commands. //! commands.
use crate::common::WasmFeatures; use crate::common::WasmFeatures;
use anyhow::{Context, Error, Result}; use anyhow::{Error, Result};
use std::path::PathBuf; use std::path::PathBuf;
use std::str::FromStr; use std::str::FromStr;
use std::string::ToString; use std::string::ToString;
use std::sync::Arc; use std::sync::Arc;
use structopt::StructOpt; use structopt::StructOpt;
use wasmer::*; use wasmer::*;
#[cfg(feature = "compiler")]
use wasmer_compiler::CompilerConfig; use wasmer_compiler::CompilerConfig;
#[derive(Debug, Clone, StructOpt)] #[derive(Debug, Clone, StructOpt)]
@@ -104,13 +105,13 @@ impl StoreOptions {
// Auto mode, we choose the best compiler for that platform // Auto mode, we choose the best compiler for that platform
cfg_if::cfg_if! { cfg_if::cfg_if! {
if #[cfg(all(feature = "cranelift", target_arch = "x86_64"))] { if #[cfg(all(feature = "cranelift", target_arch = "x86_64"))] {
return Ok(CompilerType::Cranelift); Ok(CompilerType::Cranelift)
} }
else if #[cfg(all(feature = "singlepass", target_arch = "x86_64"))] { else if #[cfg(all(feature = "singlepass", target_arch = "x86_64"))] {
return Ok(CompilerType::Singlepass); Ok(CompilerType::Singlepass)
} }
else if #[cfg(feature = "llvm")] { else if #[cfg(feature = "llvm")] {
return Ok(CompilerType::LLVM); Ok(CompilerType::LLVM)
} else { } else {
bail!("There are no available compilers for your architecture"); bail!("There are no available compilers for your architecture");
} }
@@ -303,7 +304,7 @@ impl StoreOptions {
engine.to_string() engine.to_string()
), ),
}; };
return Ok((engine, engine_type)); Ok((engine, engine_type))
} }
} }
@@ -363,16 +364,14 @@ impl StoreOptions {
engine.to_string() engine.to_string()
), ),
}; };
return Ok((engine, engine_type)); Ok((engine, engine_type))
} }
/// Get the store (headless engine) /// Get the store (headless engine)
pub fn get_store(&self) -> Result<(Store, EngineType, CompilerType)> { pub fn get_store(&self) -> Result<(Store, EngineType, CompilerType)> {
// Get the tunables for the current host // Get the tunables for the current host
let tunables = Tunables::default(); let tunables = Tunables::default();
let (engine, engine_type) = self let (engine, engine_type) = self.get_engine_headless(tunables)?;
.get_engine_headless(tunables)
.with_context(|| "No compilers enabled. Operating in headless mode")?;
let store = Store::new(engine); let store = Store::new(engine);
Ok((store, engine_type, CompilerType::Headless)) Ok((store, engine_type, CompilerType::Headless))
} }