seed-rs / seed-quickstart-webpack

Template for web apps with Seed (Rust framework), TailwindCSS and Webpack.
https://quickstart-webpack.seed-rs.org
Other
110 stars 13 forks source link

Minimize WASM size #9

Open MartinKavik opened 4 years ago

MartinKavik commented 4 years ago

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 commented 4 years ago

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

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

MartinKavik commented 4 years ago
MartinKavik commented 4 years ago

How to reduce WASM size:

TatriX commented 4 years ago

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 commented 4 years ago

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 commented 4 years ago

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

alun commented 4 years ago

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 commented 4 years ago

@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.