mirror of
https://github.com/mii443/wasmer.git
synced 2025-12-07 13:18:20 +00:00
Improved cache mechanism
This commit is contained in:
2
lib/cache/src/cache.rs
vendored
2
lib/cache/src/cache.rs
vendored
@@ -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>;
|
||||||
}
|
}
|
||||||
|
|||||||
2
lib/cache/src/filesystem.rs
vendored
2
lib/cache/src/filesystem.rs
vendored
@@ -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();
|
||||||
|
|
||||||
|
|||||||
@@ -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)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
17
src/store.rs
17
src/store.rs
@@ -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))
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user