Skip to content

Commit

Permalink
Document aggressive inlining options (#46)
Browse files Browse the repository at this point in the history
Co-authored-by: Yan Chen <[email protected]>
  • Loading branch information
kentosugama and chenyan-dfinity committed Sep 27, 2023
1 parent 36d36e9 commit d8d3b43
Showing 1 changed file with 14 additions and 2 deletions.
16 changes: 14 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,13 @@ Usage: `ic-wasm <input.wasm> info`

Remove unused functions and debug info.

Note: The `icp` metadata sections are preserved through the shrink.

Usage: `ic-wasm <input.wasm> -o <output.wasm> shrink`

Optionally invoke wasm optimizations from [`wasm-opt`](https://github.com/WebAssembly/binaryen).
### Optimize

Invoke wasm optimizations from [`wasm-opt`](https://github.com/WebAssembly/binaryen).

The optimizer exposes different optimization levels to choose from.

Expand All @@ -69,8 +73,16 @@ The recommended setting (O3) reduces cycle usage for Motoko programs by ~10% and

Note: The `icp` metadata sections are preserved through the optimizations.

Usage: `ic-wasm <input.wasm> -o <output.wasm> optimize <level>`

There are two further flags exposed from `wasm-opt`:
- `--inline-functions-with-loops`
- `--always-inline-max-function-size <FUNCTION_SIZE>`

These were exposed to aggressively inline functions, which are common in Motoko programs. With the new cost model, there is a large performance gain from inlining functions with loops, but also a large blowup in binary size. Due to the binary size increase, we may not be able to apply this inlining for actor classes inside a Wasm module.

Usage: `ic-wasm <input.wasm> -o <output.wasm> shrink --optimize <level>`
E.g.
`ic-wasm <input.wasm> -o <output.wasm> optimize O3 --inline-functions-with-loops --always-inline-max-function-size 100`

### Resource

Expand Down

0 comments on commit d8d3b43

Please sign in to comment.