-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
Large file size with fetch example? #1078
Comments
Thanks for the report! Sounds like you've already skimmed over (at least) the guide for making small wasm binaries, and after all the low-hanging fruit is out of the way the main contenders left to reduce the size here are more invasive tools and techniques The
That's actually quite a lot to pack into 100KB! Reducing the size here would come about from algorithmic changes, such as relying on JS's JSON parser or avoiding all runtime panics in the code itself (extra hard mode). Does that help explain what's going on? |
Yes it does, thank you! It sounds like reducing the code size here would involve replacing
I wish Rust had an opt-in feature to disallow any panicing code at compile time, that would be really useful! |
Perhaps! Most likely no, though. I think the generate JS bindings will tend to get a bit smaller, but the Rust side of things will likely remain about the same. Hard to say though for certain as we don't have any actual implementations yet! This is something where while it'd be awesome tends to not be a 1:1 tradeoff with JS and wasm file sizes. If you trade N bytes of JS for N bytes of wasm you're unlikely to reach feature parity with the JS nowadays (unfortunately). Wasm is simply so small (the specification) and it has had so little time to develop good standards (like CDNs for commonly used JS libraries) that it's still a "bring your own runtime" situation. Fear not though! File size is only one metric towards what's probably the most important metric, time to user interaction. Wasm, while often larger than equivalent JS, compiles much quicker than JS and can often get up and running in the engine far more quickly than JS. Wasm, using In any case, it's good to measure either way for your local use case!
|
That is a great point that I hadn't thought of. Thanks! |
Replacing As an example, I have a stdweb app which parses 50 MBs of JSON:
So So you might have to make a code size vs code performance trade-off. And as always: measure the performance in your own app. |
Compiling the
fetch
example here: https://github.com/rustwasm/wasm-bindgen/tree/master/examples/fetchGenerates a larger
.wasm
file than expected at 155KB, which can be reduced to115KB
withwasm-opt
.I've copied the source to my own project and compiled with these commands:
I have this in my
Cargo.toml
file:Is there any way to shrink this file down? 100KB is kind of a lot for just fetching/deserializing some JSON.
The text was updated successfully, but these errors were encountered: