message: Integrate weighted InMemoryCache in Cache
diff: @@ -16,6 +16,9 @@ use crate::wasm_backend::{compile_and_use, compile_only, make_runtime_store};
  const WASM_DIR: &str = "wasm";
  const MODULES_DIR: &str = "modules";
  +// Rounded-up average of Module size to optimized wasm size ratio
  +// Based on `examples/module_size.sh`, and the (optimized) cosmwasm-plus modules
  +const OPTIMIZED_WASM_SIZE_FACTOR: usize = 18;
  #[derive(Debug, Default, Clone, Copy)]
  pub struct Stats {
  @@ -203,7 +206,11 @@ where
  self.stats.hits_fs_cache += 1;
  let instance =
  Instance::from_module(&module, backend, options.gas_limit, options.print_debug)?;
  - self.memory_cache.store(checksum, module)?;
  + // Serializes module to get the size
  + // FIXME? Use just an estimate (average) of the module size
  + // let size = ESTIMATED_MODULE_SIZE.0;
  + let size = module.serialize()?.len();
  + self.memory_cache.store(checksum, module, size)?;
  return Ok(instance);
  }
  @@ -218,7 +225,8 @@ where
  let instance =
  Instance::from_module(&module, backend, options.gas_limit, options.print_debug)?;
  self.fs_cache.store(checksum, &module)?;
  - self.memory_cache.store(checksum, module)?;
  + let size = wasm.len() * OPTIMIZED_WASM_SIZE_FACTOR;
  + self.memory_cache.store(checksum, module, size)?;
  Ok(instance)
  }
  }
  