-
Notifications
You must be signed in to change notification settings - Fork 3.2k
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 caching of wasm compilation in our shell .html file #4711
Comments
(@kripken: I can work on this as well) |
Sounds good, thanks. I think we just need a little code in Although, it might be nice to consider caching more generally, perhaps we could share code with the asset cache? Just a thought. |
We should also use the async wasm compilation APIs while adding this async caching stuff. |
From discussion in that issue, we also need to have the imports present when using the new async compilation APIs, and that's not easy to make work because (1) we have the imports only in the middle of the JS, so we can't fire of compilation in the HTML, and (2) we synchronously send the imports and receive the exports. Long-term we might want to look for a new compilation mode that is fully async. In the short term, the best option seems to be to add an indirection layer on the exports, perhaps like @juj, I can do that async stuff, but all this interacts with caching, so we should probably plan it all together here before we start. |
(We should probably open an issue for the async+imports stuff specifically, but delaying that so we can do the planning here in one place due to the interaction with caching.) |
Async+imports PR is now up: #4867 I don't think it affects the IndexedDB stuff. Should be easy to fit in. |
Actually, I find myself being one of these users being named in the inital post... |
Embind would not interact with caching wasm to IndexedDB. Currently we don't yet have a built-in machinery to cache wasm to IndexedDB. The reason has been that a simple caching scheme is probably useful only to get started, but in a real world shipped application one will want to make sure wasm download, compilation and caching is done parallel with other site load actions and that the cache is integrated with other cached data so that apps don't need to interact with several caches. At that point, people would be asking how to disable any built-in wasm caching so that it doesn't get in the way. You can follow the MDN guide to do this to your .html shell page. Another example you can follow is the html page at http://mzl.la/webassemblydemo, which hooks into Emscripten runtime to manually download and cache. |
Thanks a lot for that info. I'll look into the zen garden demo. |
Thinking a little about this now, the best guidelines seem to be at https://developer.mozilla.org/en-US/docs/WebAssembly/Caching_modules with example code. I am a little worried about code size, though. Perhaps we should have it as an option? @sunfishcode made a good point offline, that for small wasm files you really don't want caching anyhow (they compile quickly, and the overhead of doing IDB operations might be larger; and for them, the code size of adding IDB handling is more noticeable). So perhaps this should be on or off by default based on the wasm size? Makes logical sense, although it may be somewhat surprising in practice. |
What's the plan with this issue? The outcome of PR #6661, which was an attempt to implement this, makes it sound like wasm caching will not be a thing still. Is it going to be just a wait until a different caching mechanism is agreed on? Slightly contrary to the IDB direction, I've still been looking into doing IDB caching in my application for the time being. I feel like it might be useful to expose the It would make it even possible to manually give the |
Browsers have decided that IDB is not the best way to cache wasm compilations, and there is work on alternatives that are more promising (simpler, more likely to work consistently, etc.). Hopefully we'll have something to experiment with there soon. We could add an option to save the wasm module and instance, if it's useful. I think we don't want it on by default though, as if the module and instance are not saved anywhere the browser may be able to free some memory. |
That's a fair point I didn't consider. I suppose an optional callback like |
This issue has been automatically marked as stale because there has been no activity in the past year. It will be closed automatically if no further activity occurs in the next 7 days. Feel free to re-open at any time if this issue is still relevant. |
Since in wasm we need to cache explicitly to IndexedDB, implement an easy code snippet to bundle the machinery to do so so that it matches the way that asm.js works, for people who don't need to care about specific details of caching.
The text was updated successfully, but these errors were encountered: