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

Implement a cache to not compile the Wasm module everytime #18

Closed
Hywan opened this issue Mar 13, 2019 · 6 comments
Closed

Implement a cache to not compile the Wasm module everytime #18

Hywan opened this issue Mar 13, 2019 · 6 comments
Labels
📦 component-extension About the PHP extension written in C/C++ 📦 component-runtime About the Wasm runtime 🎉 enhancement New feature or request

Comments

@Hywan
Copy link
Contributor

Hywan commented Mar 13, 2019

The idea is basically to add a cache, so that we don't have to validate & compile etc. the whole module everytime. It will improve grately the execution speed.

There is no API in wasmer-runtime-c-api yet. I need to work on that. Maybe we will implement that outside the wasmer-runtime-c-api crate.

@Hywan Hywan added 🎉 enhancement New feature or request 📦 component-extension About the PHP extension written in C/C++ 📦 component-runtime About the Wasm runtime labels Mar 13, 2019
@xtuc
Copy link

xtuc commented Mar 13, 2019

I was about to open a issue to ask you a question; could you please clarify the lifetime of a WebAssembly Instance/Module?

I would like to avoid to instantiate the WebAssembly module for each request. You are mentioning a cache for the module, I'm assuming that's to avoid running possible side-effects at instantiation, right?

However, I think it would be useful to explicitly ask to keep the instance in cache too (forgive my ignorance about PHP extensions). Would that be possible?

@Hywan
Copy link
Contributor Author

Hywan commented Mar 14, 2019

So far, the lifetime of a module is constrained by the lifetime of a PHP execution. It starts when your run wasm_new_instance, and it is destroyed when the instance is destroyed (so either with unset or by waiting the end of the execution).

I would like to avoid to instantiate the WebAssembly module for each request

This issue is to only avoid the compilation step. The cache will contain a module then. I'm likely to use https://github.com/wasmerio/wasmer/blob/master/lib/runtime-core/src/cache.rs.

You are mentioning a cache for the module, I'm assuming that's to avoid running possible side-effects at instantiation, right?

Do you mean caching the module instead of an instance? Yes. I don't want to cache the instance. That would be a terrible idea from my point of view, since it comes with the memory pages, tables etc.

However, I think it would be useful to explicitly ask to keep the instance in cache too (forgive my ignorance about PHP extensions). Would that be possible?

It is, but I don't want to address that part yet. I want to first cache the module, and see how it impacts the performance in general.

It's trickier to cache an instance. And it depends of the usecases. Let's see! … or do you have a specific usecase in mind?

@xtuc
Copy link

xtuc commented Mar 14, 2019

It's trickier to cache an instance. And it depends of the usecases. Let's see! … or do you have a specific usecase in mind?

Well I like PHP but here I have an occassion to avoid it. I don't have a specific use case in mind, but everything that would retain some kind of state. For instance, that could replace memcached with an app specific cache!

I agree that this shouldn't be the default caching strategy, but an explicit API would be great. I believe it's out-of-scope for now, just saying it would be nice to have.

@Hywan
Copy link
Contributor Author

Hywan commented Mar 14, 2019

I'm starting drafting it. More to come tomorow :-). I will probably ping you in the PR, if you're agree?

@xtuc
Copy link

xtuc commented Mar 14, 2019

Sure, I'm happy to help.

@Hywan
Copy link
Contributor Author

Hywan commented Mar 15, 2019

Waiting on wasmerio/wasmer#271.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
📦 component-extension About the PHP extension written in C/C++ 📦 component-runtime About the Wasm runtime 🎉 enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants