This is outdated documentation for Sycamore.
For up-to-date documentation, see the latest version (v0.8).
Reducing binary size
Note: More information about reducing binary size can be found in the Rust Wasm Book.
Building in release mode
A common mistake when building a Wasm binary is to forget to build in release mode. If you are using
trunk
, simply add the --release
flag to the build command:
wee_alloc
wee_alloc
is a memory allocator focused on targeting
WebAssembly, producing a small .wasm code size, and having a simple, correct implementation.
Replacing the default allocator with this one will result in a smaller binary size at the expense of
speed and memory overhead.
// Use `wee_alloc` as the global allocator.
static ALLOC: WeeAlloc = INIT;
Cargo.toml
It is possible to configure release builds to be smaller by using various flags and configurations
in your Cargo.toml
file.
[]
# Do not perform backtrace for panic on release builds.
= 'abort'
# Perform optimizations on all codegen units.
= 1
# Optimize for size.
= 's' # or 'z' to optimize "aggressively" for size
# Enable link time optimization.
= true
wasm-opt
If you are using trunk
, add this line to your index.html
to enable wasm-opt
: