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

feat: Add a Cache API #26

Merged
merged 9 commits into from
Mar 20, 2019
Merged

feat: Add a Cache API #26

merged 9 commits into from
Mar 20, 2019

Conversation

Hywan
Copy link
Contributor

@Hywan Hywan commented Mar 15, 2019

Fix #18.
Blocked by #25 (this PR contains all its commits).

This PR adds a Wasm\Cache API:

$cache = new Wasm\Cache\Filesystem(CACHE_DIRECTORY);

if ($cache->has(KEY)) {
    $module = $cache->get(KEY);
} else {
    $module = new Wasm\Module(__DIR__ . '/simple.wasm');
    $cache->set(KEY, $module);
}

$instance = $module->instantiate();
$instance->sum(1, 2);

The cache API is based on PSR-16.

@Hywan Hywan added 🎉 enhancement New feature or request 🧪 tests I love tests 📦 component-library About the PHP library build on top of the extension 📚 documentation Do you like to read? labels Mar 15, 2019
@Hywan Hywan self-assigned this Mar 15, 2019
@Hywan
Copy link
Contributor Author

Hywan commented Mar 16, 2019

Any thoughts on this @xtuc?

@xtuc
Copy link

xtuc commented Mar 16, 2019

Serializing the module to a string seems a bit inefficient to me, and I doubt someone would manipulate the string in PHP. However, manipulating an opaque pointer to the compiled module seems useful. A use-case that comes to my mind is the threading proposal, which requires to instantiate the same compiled Module multiple times.

I'm really not aware of PHP extensions work, but is there a way to keep something in memory for multiple requests? Ideally to me, the opaque pointer would be managed by wasmer.

@Hywan Hywan force-pushed the feat-module-caching branch from a47195c to 5bbc228 Compare March 20, 2019 09:31
@Hywan
Copy link
Contributor Author

Hywan commented Mar 20, 2019

It is possible to get a persistent data in PHP yes. I don't know how, but I know it is :-).

@nikic Do you think it's a good idea to get a persistent opaque pointer between PHP requests? If yes, any idea how to implement that? Thanks!

@nikic
Copy link

nikic commented Mar 20, 2019

@Hywan As long as you don't use the per-request allocator, keeping persistent data between request is (on a technical level) not a problem. You need to stick your opaque pointer into globals somewhere and have a mechanism on the PHP side for how it can be accessed again on the next request. (A common example for persistent data are persistent database resources -- but actually using resources is not necessary.)

@Hywan
Copy link
Contributor Author

Hywan commented Mar 20, 2019

@nikic Do you know if an extension already does that? Or if Zend offers an API for that? I'm interested by the persistent resource, any documentation? Thanks!

@Hywan Hywan force-pushed the feat-module-caching branch from 5bbc228 to ab8d07f Compare March 20, 2019 14:24
@Hywan Hywan marked this pull request as ready for review March 20, 2019 14:58
@Hywan Hywan merged commit 8398019 into master Mar 20, 2019
@Hywan
Copy link
Contributor Author

Hywan commented Mar 20, 2019

I'll address the persistent modules or instances in another issue.

@Hywan Hywan deleted the feat-module-caching branch April 3, 2019 09:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
📦 component-library About the PHP library build on top of the extension 📚 documentation Do you like to read? 🎉 enhancement New feature or request 🧪 tests I love tests
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants