#minimizing WASM code size

11 messages · Page 1 of 1 (latest)

wary tiger
#

Hello, are there any tricks to minimize the size of WASM contract code besides using a Cargo release profile as in the soroban examples? @hard dock you alluded to the lto option sometimes being overridden for some reason.

tiny cargo
#

if you mean the whole blob, it's possible to strip a whole bunch of SDK metadata

#

another 'trick' is to write wasm manually 🙂

eager coral
urban portal
#

a good way to reduce size is to also remove overflow checking 🙂

#

theres also the soroban contract optimize cmd with the soroban cli

hard dock
#

@wary tiger yeah you have to be quite aggressive with build settings to get LTO to work

#

the examples we have in the soroban-examples repo are set right

#
opt-level = "z"
overflow-checks = true
debug = 0
strip = "symbols"
debug-assertions = false
panic = "abort"
codegen-units = 1
lto = true```
#

you also have to have only a cdylib target type

#
crate-type = ["cdylib"]```