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

wasm-strip reduces bundle size inexplicably #543

Open
surma opened this issue Feb 12, 2019 · 12 comments
Open

wasm-strip reduces bundle size inexplicably #543

surma opened this issue Feb 12, 2019 · 12 comments

Comments

@surma
Copy link
Contributor

surma commented Feb 12, 2019

💡 Feature description

Building the default example project as a release build yields some rather big wasm modules, which might be deterring to some:

Command: wasm-pack build --release

  • stable: 1.3M
  • nightly: 771K

After running wasm-strip, the size goes down drastically:

  • stable: 1.6K
  • nightly: 1.6K

Anything speaking against running wasm-strip automatically, at least for --release?

wasm-pack 0.6.0
rustc 1.32.0 (9fda7c223 2019-01-16)
rustc 1.34.0-nightly (57d7cfc3c 2019-02-11)

@ashleygwilliams
Copy link
Member

@surma yeah! i was actually thinking about this after our in person hack sesh at the meetup. the biggest blocker to adding tools to wasm-pack is the availability of a rust library and/or linux/macOS/windows binaries (the binaries are the preferred option). would you be willing to take a look into the availability of these binaries? if they exist, adding wasm-strip should be otherwise not too difficult.

also a side note- wasm-pack defaults to release so this is a feature that would be run by default and turned off for when wasm-pack runs in --dev mode.

@fitzgen
Copy link
Member

fitzgen commented Feb 13, 2019

I think we would only want to run wasm-strip for the release profile, not debug or profiling profiles, since it will remove debug info. But I'm also a little confused because I would assume that we are already not including any custom sections in release profile builds...

Either way -- if we add support for this, we would want to control it via the toml config.

@ashleygwilliams
Copy link
Member

@fitzgen agree we'd only want it for --release, which is the "default" (i.e. not on --dev, or debug, or the others)

it certainly appears that wasm-strip does something here, perhaps it would help to figure out exactly what it does! (re: your comment re custom sections)

@surma
Copy link
Contributor Author

surma commented Feb 13, 2019

As I mentioned in the title, I definitely meant wasm-strip to only be run for release builds!

I ran Twiggy real quick:
screen shot 2019-02-13 at 8 38 02 pm

So it seems that custom sections do not get stripped.

(That being said, I think this might have been a change in 1.32 or something. I believe when I was on 1.30 the binary was way smaller)

@fitzgen
Copy link
Member

fitzgen commented Feb 14, 2019

Figured out why the DWARF isn't getting stripped: rustwasm/wasm-bindgen#1254

@ashleygwilliams
Copy link
Member

@surma could you try the newest release of wasm-bindgen and confirm this is fixed? (i'd expect that wasm-strip would make a lot less of, if no, difference if the bug is indeed fixed!)

@surma
Copy link
Contributor Author

surma commented Feb 22, 2019

I updated the wasm-bindgen dependency in my test project to 0.2.37, but sadly wasm-strip doesn’t seem to actually be invoked.

Invoking wasm-strip manually shaves off around 3k.

@ashleygwilliams
Copy link
Member

@fitzgen circling back up on this - any idea what wasm-strip is stripping? @surma can you give any more details?

@fitzgen
Copy link
Member

fitzgen commented Apr 2, 2019

wasm-bindgen doesn't ever attempt to run wasm-strip -- I think there is some kind of misunderstanding here?

I think we need to be more concrete about examples, expectations, and actual behavior here, so it would be useful to have:

  • steps to reproduce (clone this repo, run this command, etc)
  • expected behavior (the generated wasm does not have any custom sections)
  • actual behavior (the generated wasm has X and Y custom sections)

@ashleygwilliams
Copy link
Member

@surma sorry for the Extreme Delay. any status update on this? if you have a way to repro that'd be great.

@ashleygwilliams ashleygwilliams changed the title Run wasm-strip with --release wasm-strip reduces bundle size inexplicably Jul 16, 2019
@surma
Copy link
Contributor Author

surma commented Jul 16, 2019

Apologies! I lost track of this as well!

Here’s a repro repo: https://github.com/surma-dump/wasm-pack-issue-543

Repro steps:

  1. Run wasm-pack build --release
  2. Check file size of pkg/wasm_pack_issue_543_bg.wasm
  3. Run wasm-strip pkg/wasm_pack_issue_543_bg.wasm
  4. Check file size of pkg/wasm_pack_issue_543_bg.wasm again

Expected: File size remains the same

Currently observed: File size got smaller after running wasm-strip

@wdanilo
Copy link

wdanilo commented Jan 15, 2020

I've got a different story to share:

  1. Clone enso-org/ide@9d1b18d
  2. Build with ./scripts/build.sh (wrapper for wasm-pack).
  3. Check file size of target/web/basegl_bg.wasm
  4. Run wasm-strip on the file.
  5. Check the file size again.

Result: After running wasm-strip the size grows from 3.9Mb to 4.1Mb.
What is even more strange (to me) is that after running the 4.1Mb version via webpack optimizer, I got 3.83Mb output, smaller than running webpack without using wasm-strip.

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

No branches or pull requests

4 participants