Shrinking .wasm Size
Take a moment to review the build configuration options we can tweak to getsmaller .wasm
codesizes.
After enabling LTO, setting opt-level = "z"
, and running wasm-opt -Oz
, theresulting .wasm
binary shrinks to only 17,317 bytes:
Exercises
Use the toolto remove the panicking infrastructure functions from our Game of Life's
.wasm
binary. How many bytes does it save?
How much size does using shave off of the .wasm
binary?
- We only ever instantiate a single
Universe
, so rather than providing aconstructor, we can export operations that manipulate a singlestatic mut
global instance. If this global instance also uses the double bufferingtechnique discussed in earlier chapters, we can make those buffers also bestatic mut
globals. This removes all dynamic allocation from our Game ofLife implementation, and we can make it a#![no_std]
crate that doesn'tinclude an allocator. How much size was removed from the.wasm
by completelyremoving the allocator dependency?