Skip to content

Commit

Permalink
Integrate PinnedMemoryCache to Cache
Browse files Browse the repository at this point in the history
  • Loading branch information
maurolacy committed Jan 8, 2021
1 parent cce56db commit 99b1724
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion packages/vm/src/cache.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ use crate::checksum::Checksum;
use crate::compatibility::check_wasm;
use crate::errors::{VmError, VmResult};
use crate::instance::{Instance, InstanceOptions};
use crate::modules::{FileSystemCache, InMemoryCache};
use crate::modules::{FileSystemCache, InMemoryCache, PinnedMemoryCache};
use crate::size::Size;
use crate::wasm_backend::{compile_and_use, compile_only, make_runtime_store};

Expand All @@ -18,6 +18,7 @@ const MODULES_DIR: &str = "modules";

#[derive(Debug, Default, Clone, Copy)]
pub struct Stats {
pub hits_pinned_memory_cache: u32,
pub hits_memory_cache: u32,
pub hits_fs_cache: u32,
pub misses: u32,
Expand All @@ -33,6 +34,7 @@ pub struct CacheOptions {
pub struct Cache<A: Api, S: Storage, Q: Querier> {
wasm_path: PathBuf,
supported_features: HashSet<String>,
pinned_memory_cache: PinnedMemoryCache,
memory_cache: InMemoryCache,
fs_cache: FileSystemCache,
stats: Stats,
Expand Down Expand Up @@ -72,6 +74,7 @@ where
Ok(Cache {
wasm_path,
supported_features,
pinned_memory_cache: PinnedMemoryCache::new(),
memory_cache: InMemoryCache::new(memory_cache_size),
fs_cache,
stats: Stats::default(),
Expand Down Expand Up @@ -117,6 +120,14 @@ where
options: InstanceOptions,
) -> VmResult<Instance<A, S, Q>> {
let store = make_runtime_store(options.memory_limit);
// Try to get module from the pinned memory cache
if let Some(module) = self.pinned_memory_cache.load(checksum, &store)? {
self.stats.hits_pinned_memory_cache += 1;
let instance =
Instance::from_module(&module, backend, options.gas_limit, options.print_debug)?;
return Ok(instance);
}

// Get module from memory cache
if let Some(module) = self.memory_cache.load(checksum, &store)? {
self.stats.hits_memory_cache += 1;
Expand Down

0 comments on commit 99b1724

Please sign in to comment.