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

Minimize WASM size #9

Open
MartinKavik opened this issue Dec 13, 2019 · 8 comments
Open

Minimize WASM size #9

MartinKavik opened this issue Dec 13, 2019 · 8 comments

Comments

@MartinKavik
Copy link
Member

What can be added into Cargo.toml:

[profile.release]
lto = true
opt-level = 'z'
codegen-units = 1

Other ideas?

@TatriX - you (will) have the project based on the current seed-quickstart-webpack template - I would be glad if you can confirm, that it helps or if you find other options. Don't hurry, I plan to integrate it to next release without ETA. Thanks!

@TatriX
Copy link
Member

TatriX commented Dec 13, 2019

What is the current bundle size?
I think we can put similar chart to the site/readme:


Source: https://elm-lang.org/

@MartinKavik
Copy link
Member Author

  • Seed RealWorld is based on a rust quickstart that isn't very optimized (I plan to work on that quickstart but in several months at the earliest) - it's gzipped wasm file (by Netlify) is 404 KB.

  • kavik.cz (based on this quickstart) is 119 KB (without suggested optimizations above).

  • seed-rs.org (based on this quickstart) is 179 KB (without suggested optimizations above and all text content is inlined into binary).

@MartinKavik
Copy link
Member Author

How to reduce WASM size:

@TatriX
Copy link
Member

TatriX commented Dec 13, 2019

I think we cannot directly compare js bundle size vs wasm bundle size, because as far as I know wasm was optimized for streaming and interpretation speed, i.e. wasm bundle with equal size should be faster because browser don't need to parse the whole script.

That being said, I think bundle size is already quite good.

@MartinKavik
Copy link
Member Author

MartinKavik commented Dec 13, 2019

That being said, I think bundle size is already quite good.

Yeah, that's the reason why it isn't my priority now, but it can be better. And I think that the small size is also quite good for marketing - especially in comparison with e.g. Blazor and other wasm frameworks.

@MartinKavik
Copy link
Member Author

Update in the latest version (0.4.1) - I've added flags from the first comment and it reduced WASM file size:

  • Before: 520 KB (141 gzipped)
  • After: 348 KB (124 gzipped)

@alun
Copy link

alun commented Jun 13, 2020

It definitely would be worthwhile to get some improvements here I'm comparing todo mvc example in yew https://todomvc.yew.rs/ and in seed which I build with cargo make build from seed/examples/todomvc.

Sizes of wasm output file relate as (yew/seed):

82303/765571 = 0.10750 gzipped
229422/2801459 = 0.08189 ungzipped

So it looks like yew is 90% smaller which makes a huge difference IMO.

Disclaimer: I'm new to both so maybe I don't know about some required optimisation flags yet.

@MartinKavik
Copy link
Member Author

@alun cargo make build generates a huge and slow debug build. Try something like cargo make build_release. I've just tried to build a new Seed TodoMVC (it's not published yet, I'm writing a new tutorial for seed-rs.org) and it has 320KB uncompressed. So the gzipped version should be comparable to the yew's one. Also we plan to optimize Seed for size and speed in the future, so it will be much better I hope.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants