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

Split the wasm file #4555

Open
takkuumi opened this issue Apr 22, 2022 · 5 comments
Open

Split the wasm file #4555

takkuumi opened this issue Apr 22, 2022 · 5 comments
Labels
C-Performance A change motivated by improving speed, memory usage or compile times O-Web Specific to web (WASM) builds

Comments

@takkuumi
Copy link

Bevy output wasm is big , 3d-scene wasm file was 14MB, gzip size is 3.6.

Is it possible to split a single wasm file into different modules to better utilize browser network concurrency?

@takkuumi takkuumi added C-Enhancement A new feature S-Needs-Triage This issue needs to be labelled labels Apr 22, 2022
@alice-i-cecile alice-i-cecile added C-Performance A change motivated by improving speed, memory usage or compile times O-Web Specific to web (WASM) builds and removed S-Needs-Triage This issue needs to be labelled C-Enhancement A new feature labels Apr 22, 2022
@jakobhellermann
Copy link
Contributor

I don't think this is possible in wasm. There's an open issue with some discussion WebAssembly/design#1166, but I can't find anything else. On other platforms you can also split the debuginfo into a separate file, but that doesn't seem possible on wasm. On a release build you can just remove the debug info instead which further cuts file size: #3978 (comment). With all the options in that comment I can go from 17mb to 1.7mb which might be enough for you.

@takkuumi
Copy link
Author

I don't think this is possible in wasm. There's an open issue with some discussion WebAssembly/design#1166, but I can't find anything else. On other platforms you can also split the debuginfo into a separate file, but that doesn't seem possible on wasm. On a release build you can just remove the debug info instead which further cuts file size: #3978 (comment). With all the options in that comment I can go from 17mb to 1.7mb which might be enough for you.

Yes,But there's an other way to resolve this. We can split some standalone module, and then use webworker to post message.

@druskus20
Copy link

druskus20 commented Apr 9, 2024

Wasm code splitting is, to the best of my knowledge, not available in Rust.
There's a 2018 issue discussing it rustwasm/team#52

And it is implemented in C++ https://github.com/WebAssembly/binaryen/blob/102c3633d2378457dae1f5e239fd63ad80eefb92/src/tools/wasm-split/wasm-split.cpp#L339 (and it is used by wasm-opt I believe)

In the case of web at least, the limitation is still lazy loading the modules. https://emscripten.org/docs/optimizing/Module-Splitting.html#running-on-the-web

@jbms
Copy link

jbms commented May 2, 2024

See this issue where I posted a prototype that addresses exactly this: rustwasm/wasm-bindgen#3939

@daxpedda
Copy link
Contributor

To at least get rid of the debug info, I'm using wasm2map to generate a source map and then strip the debug info from the Wasm file.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-Performance A change motivated by improving speed, memory usage or compile times O-Web Specific to web (WASM) builds
Projects
None yet
Development

No branches or pull requests

6 participants