3

I recently wrote a pallet that uses a (non-substrate) Rust crate as a dependency. This crate conveniently supports no-std and Wasm, but it is also quite extensive and there's a lot of code that my pallet simply doesn't use.

When I compile a runtime with this pallet, the resulting wasm blob is way too big (in the order of Mb).

Is there a clever way to make sure that compilation will only include wasm imports that my pallet actually uses, preventing unnecessary bloating of the runtime wasm?

1 Answer 1

2

In general no, unless the code is feature gated in the library itself. There's simply no way to prove that some code is "unnecessary" if it is under the same feature umbrella as the import you're using. Although I bet that the same rust practices to reduce the size of the target can help, but you'll have to try them out:

[profile.release]
lto = true

I found this code profile analyzer for wasm : https://github.com/rustwasm/twiggy that you may use to inspect what's taking up size and probably rewrite the code from the library that you're importing.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.