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

Use twiggy to analyze contract binaries for size optimization opportunities #873

Closed
Tracked by #9354
cmichi opened this issue Jul 22, 2021 · 1 comment
Closed
Tracked by #9354
Labels
A-examples [examples] Work item A-ink_storage [ink_storage] Work Item B-research Research task that has open questions that need to be resolved. P-high High priority issue.

Comments

@cmichi
Copy link
Collaborator

cmichi commented Jul 22, 2021

Credit for this idea goes to @athei. ink! is currently mostly optimized for speed rather than code size. We can use the twiggy tool to analyze the contract binaries for size optimization opportunities.

We should use the tool to inspect our example contracts to find out where to start optimizing.

  1. Install @athei's twiggy fork
cargo install --git https://github.com/athei/twiggy
  1. Compile a contract with debug symbols (currently cargo contract master is needed for this)
cargo +nightly contract build --generate code-only --keep-debug-symbols
  1. Analyze with twiggy
twiggy dominators target/ink/erc20.wasm
twiggy monos target/ink/erc20.wasm
twiggy top target/ink/erc20.wasm

You can ignore the "name" section in your analysis, those are the debug symbols (function names) which are removed in a real contract.

More info on twiggy can be found here: https://rustwasm.github.io/twiggy/.

@cmichi cmichi added A-ink_storage [ink_storage] Work Item A-examples [examples] Work item B-research Research task that has open questions that need to be resolved. labels Jul 22, 2021
@cmichi cmichi added the P-high High priority issue. label Jul 26, 2021
@cmichi
Copy link
Collaborator Author

cmichi commented Sep 13, 2021

I'm closing this issue, since we've now created a couple of follow-up issues (see paritytech/substrate#9354 for the tracking issue).

As a sidenote I'm adding that

RUSTFLAGS="-Zsymbol-mangling-version=v0" cargo +nightly llvm-lines --release

will show you generics monomorphization bloat (source).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-examples [examples] Work item A-ink_storage [ink_storage] Work Item B-research Research task that has open questions that need to be resolved. P-high High priority issue.
Projects
None yet
Development

No branches or pull requests

1 participant