Skip to content

Reduce contract binary size

jjy edited this page Jun 30, 2020 · 1 revision

Make sure remove all string formatting code

This suggestion is from the article Formatting is Unreasonably Expensive for Embedded Rust.

We should make sure our code and dependencies crates do not contain format! and formatting version panic! macros, since these macros generated code increases the size of our binary craziness.

Note, the non-formatting version panic! is OK to use. The debug! macro is also OK to use since debug! generates no code in the release mode.

Follow the steps to check your contract:

  1. make sure to use 0.4.1 or a later version ckb-std, which contains no formatting macro.
  2. check your other dependencies to make sure there're no formatting macro be used.
  3. check contract code.
  4. try to use opt-level = 's' options in Cargo.toml, which generates a smaller binary for demo contracts.