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

Experiment with some wasm-opt options #110

Closed
Tracked by #9354
Robbepop opened this issue Nov 18, 2020 · 4 comments
Closed
Tracked by #9354

Experiment with some wasm-opt options #110

Robbepop opened this issue Nov 18, 2020 · 4 comments
Labels
enhancement New feature or request

Comments

@Robbepop
Copy link
Contributor

We currently are not using wasm-opt's --strip-debug --vacuum --dce options. They might be useful to us to reduce the resulting .wasm files. Experimentation needed.

@Robbepop Robbepop added the enhancement New feature or request label Nov 18, 2020
@cmichi
Copy link
Collaborator

cmichi commented Nov 18, 2020

In that regard experimenting with wasm-opt optimization flags could also have some benefits. Currently we just pass 3 by default. If you execute cargo +nightly contract build --help you'll see the other possibilities.

In general we should review the other flags from wasm-opt --help as well. Could be that there are some additional ones in there which have a big impact.

@HCastano
Copy link
Contributor

I've been playing around a bit with some of the optimizations options using some (but not
all) of our example contracts.

For reference, the original sizes with ink! on hc-bump-allocator and cargo-contract on master
are in the table below.

Contract Original Optimized
erc20 51.8K 30.5K
trait-erc20 52.3K 31.0K
erc1155 65.2K 45.3K
erc721 68.3K 41.1K
dns 44.2K 25.3K
multisig_plain 86.2K 53.6K
  1. Setting cargo-contract to --optimization-passes s
    This saves us ~0.2-0.3K.

  2. Setting cargo-contract to --optimization-passes z
    Same as (1).

  3. Adding --vaccum option to wasm-opt
    This increases the size by ~0.2-0.3K.

  4. Adding --strip-debug option to wasm-opt
    Same as (3).

  5. Adding --dae-optimizing option to wasm-opt
    Same as (3).

I think right now changing the opt level default from -O3 to at least -Os is the most
sensible thing to do.

@athei
Copy link
Contributor

athei commented Jul 20, 2021

There are a lot of optimization options. I have no idea which are on by default and which are not. Would be nice to find that out. I guess the source code should reveal this information.

For example, --strip-debug is on by default. To keep the debug symbols -g is needed.

@cmichi
Copy link
Collaborator

cmichi commented Sep 13, 2021

If nobody speaks up in the next days I'll close this issue. We've already set

-Oz  execute default optimization passes, super-focusing on code size

as a consequence of this issue and it lead to some savings.

We've done some experimenting of individual flags which seemed reasonable, but no further big finding was found. There are a lot more options we could try:

$ wasm-opt --help | grep "\-\-" | wc -l
167

But it seems that the potential of finding another big thing is low, whereas we have a number of ideas in paritytech/substrate#9354 now, which will definitely lead to significant size improvements. So I think it's reasonable to rather focus our effort there.

@cmichi cmichi closed this as completed Sep 20, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

4 participants