-
Notifications
You must be signed in to change notification settings - Fork 329
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1982 from CosmWasm/one-engine-per-module
Store engine together with Module to mitigate memory increase issue
- Loading branch information
Showing
7 changed files
with
206 additions
and
124 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,30 @@ | ||
use wasmer::Module; | ||
use wasmer::{Engine, Module}; | ||
|
||
/// Some manual tests on Simon's machine showed that Engine is roughly 3-5 KB big, | ||
/// so give it a constant 10 KiB estimate. | ||
#[inline] | ||
pub fn engine_size_estimate() -> usize { | ||
10 * 1024 | ||
} | ||
|
||
#[derive(Debug, Clone)] | ||
pub struct CachedModule { | ||
pub module: Module, | ||
/// The runtime engine to run this module. Ideally we could use a single engine | ||
/// for all modules but the memory issue described in <https://github.com/wasmerio/wasmer/issues/4377> | ||
/// requires using one engine per module as a workaround. | ||
pub engine: Engine, | ||
/// The estimated size of this element in memory. | ||
/// Since the cached modules are just [rkyv](https://rkyv.org/) dumps of the Module | ||
/// instances, we use the file size of the module on disk (not the Wasm!) | ||
/// as an estimate for this. | ||
/// Note: Since CosmWasm 1.4 (Wasmer 4), Store/Engine are not cached anymore. | ||
/// The majority of the Module size is the Artifact. | ||
/// | ||
/// Between CosmWasm 1.4 (Wasmer 4) and 1.5.2, Store/Engine were not cached. This lead to a | ||
/// memory consumption problem. From 1.5.2 on, Module and Engine are cached and Store is created | ||
/// from Engine on demand. | ||
/// | ||
/// The majority of the Module size is the Artifact which is why we use the module filesize as the estimate. | ||
/// Some manual tests on Simon's machine showed that Engine is roughly 3-5 KB big, so give it a constant | ||
/// estimate: [`engine_size_estimate`]. | ||
pub size_estimate: usize, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.