-
Notifications
You must be signed in to change notification settings - Fork 59
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
Splitting and lazy loading wasm modules #52
Comments
JavaScript has an official way to lazy-load modules: the I'm not sure if there are plans to support However, it is important to note that the |
Wasm modules don't support splitting up well yet, as shared components like allocators must be included in every component. For this to work well, we'd need dynamic linking support.... right now apparently they want you to go through js but I doubt that this is fast enough for usage in e.g. an allocator. IDK though, maybe js engines can inline such a layer. |
The plan is to eventually have WASM modules just be ES modules. Once that's in place, |
Well I am not sure, as @est31 points out there is an ambiguity in sharing allocators and dynamic linking of the wasm modules. using them as |
I think we could split at the crate boundary, assuming one of
Exported generics, if allowed, would have to be monomorphised into the downstream crate, I guess. Basically, it is the same issues we run into when splitting an existing binary across multiple dylibs... Which Rust doesn't have a great story for. |
I wonder if we can make any progress on this. wasm-bindgen now supports There is documentation on the webassembly website about dynamic loading using module imports/exports. It would be nice to be able to compile libraries as dylibs that can be linked against for other components. |
Any news on this? |
FYI I have plans to implement profile-guided module splitting functionality in Binaryen to facilitate lazy loading of code that is not needed for startup. Once that work is farther along, perhaps we can coordinate on a way to expose that functionality ergonomically in wasm-pack. |
Hi! Is there any progress in this regards? :) |
FWIW Binaryen now has a This should work out of the box with Rust when compiling to the wasm32-unknown-emscripten target, but that's unfortunately not compatible with wasm-pack. |
Oh, that's super interesting! Thanks for letting me know. I'm so sad that wasm-pack does not support it though :/ |
I'm not familiar with how the |
|
I've built a prototype that addresses this issue in what I think is quite an elegant way. See rustwasm/wasm-bindgen#3939 |
This issue arises based on this discussion.
When converting an entire library into a wasm module, it is quite often we end up in huge size wasm output (~equal to the binary size). This will surely affect the wide usage of wasm.
One important usage of wasm is to use native libraries in the web application straightaway for the speed and other benefits. Splitting of wasm into chunks / modules will have its own benefits. This will probably followed by lazy-loading of the binaries as and when needed.
While, streaming compiler looks promising for libraries that are medium sized. It is better to provide an option to chunk the wasm and load them easily.
The text was updated successfully, but these errors were encountered: