Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Avoid serialization/deserialization of artifacts in InMemoryCache #697

Closed
webmaster128 opened this issue Jan 6, 2021 · 0 comments · Fixed by #703
Closed

Avoid serialization/deserialization of artifacts in InMemoryCache #697

webmaster128 opened this issue Jan 6, 2021 · 0 comments · Fixed by #703

Comments

@webmaster128
Copy link
Member

Right now we seralize a Module in InMemoryCache::store and deserialize it in InMemoryCache::load. This operation is costy, as discovered here: #603. Being able to avoid it brings down startup times of contracts cached in memory from 1-2ms to about 50µs.

Using Wasmer 0.17, we could cache modules in memory without serialization but with Wasmer 1.0 we create new Modules in every load in order to be able to set a new Store.

Possible solutions

  1. Allow swapping out the Store of a Module: In Allow decomposition and composition of Modules without serialization wasmerio/wasmer#1933 it is discussed if we can replace a Store of an existing module but it is unclear if this is doable.
  2. Create a new Module from an Artifact without serializing. This does not work, see Cache Artifacts directly instead of their serialization #666.
  3. Instantiate multiple instances from one Module without using a new Store. This is the recommended way to create many instances.

Why use a new Store for every instance

An InMemoryCache lives as long as a higher level Cache. Right now, pass a memory_limit via InstanceOptions to Cache::get_instance. This allows us to use a different memory limit for every Instance. However, this flexibility is not needed at all. CosmWasm/wasmvm@bbeb7a9#diff-24ee2abbb4556b154f9bada8de5f7961a957bd2267b3cdeeeaf23e619769c5c7 shows how one memory limit is configured for all contract executions of one VM. So if we remove memory_limit from InstanceOptions and store it as a field to the Cache, we can use the same memory limit for all instances. Then we don't need a new Store for every instance. This allows us to cache Modules directly in InMemoryCache.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants