Unexplained Wasm size increase in Rust

Hi, so the Dragginz content canister has been around 900K for the past month or so. Yesterday I committed a load of changes all together and then checked the Wasm size and it was now 1.2 MB. The unzipped size jumped from 9 to 11 megs.

I had just added about 300K of schema code into a include_str! macro, so I assumed it was that, as I found out that macro didn’t compress the contents. So I went back to the old way I was doing it with a static &str; and compiled.

Still 1.2 megs. I made the 300K code into a single “{}” and no change. I’ve now spent 4 hours painstakingly going though the commit to try and work out what happened, but nothing I change reduces the Wasm size.

cargo clean, rm -rf .dfx, rm ~/.cache/dfinity etc. nothing will reduce the size. We’ve confirmed both commit sizes on a second computer too.

I’ve even gone through the wasm-objdump to look for strings and have confirmed that in the 1.2 meg file there’s no schema whatsoever.

I am tempted just to stop trying to work out what I did and find some other way of dumping the Wasm to compare it. Could I perhaps do a wasm-objdump -h on both versions and compare headers or something?

It’s not that the new size is an issue, but I just want to know what’s going on.

Thanks!

1 Like
twiggy diff content.wasm content_old.wasm -n 10000 | more

hmmm, I may have wrapped a deserialization function as a helper method… didn’t expect that to add 25%

1 Like

Oh hi @borovan. Yes what you’ve done here is a basic misunderstanding of how the rust compiler creates monomorphizations of generic functions. Looks like that those deserialization methods are now linked because the rust compiler was stripping them before.

The code bloat isn’t that bad, 1.1 megs is still below the current limit. Twiggy and wasm-objdump are great tools to use to find out what’s going on inside the wasm!

6 Likes

Awesome, thanks - much appreciated!

Adding 300k of data and then seeing the Wasm size increase by 300k for a completely different reason though, that must have been a hard one to debug!

2 Likes

Your solo Q&A thread on a pure and deep IC dev topic in an IC developer forum is a pleasure to behold, especially after the wading through the quasi-political $#@±storm of the various SNS forum threads.

Just sayin’. Carry on.

4 Likes

That was funny, thank you