1# Tuning Wasmtime for Fast Compilation 2 3Wasmtime must compile a Wasm program before executing it. This means that, by 4default, Wasm compilation is on your critical path. In most scenarios, you can 5completely remove Wasm compilation from the critical path by [pre-compiling Wasm 6programs](./examples-pre-compiling-wasm.md). That option is not always 7available, however, and this page documents how to tune Wasmtime for fast 8compilation in these alternative scenarios. 9 10## Enable the Compilation Cache 11 12Wasmtime can be configured to use a cache, so that if you attempt to compile a 13Wasm program that has already been compiled previously, it just grabs the cached 14result rather than performing compilation all over again. 15 16See these API docs for more details: 17 18* [`wasmtime::Config::cache`](https://docs.rs/wasmtime/latest/wasmtime/struct.Config.html#method.cache) 19* [`wasmtime::CacheStore`](https://docs.rs/wasmtime/latest/wasmtime/trait.CacheStore.html) 20 21## Enable Winch 22 23Winch is Wasmtime's "baseline" compiler: for each Wasm opcode, it emits a canned 24sequence of machine instructions to implement that opcode. This makes 25compilation fast: it performs only a single, quick pass over the Wasm 26code. However, it does not perform optimizations, so the machine code it emits 27will run Wasm programs slower than Cranelift, Wasmtime's optimizing compiler. 28 29See the API docs for 30[`wasmtime::Strategy`](https://docs.rs/wasmtime/latest/wasmtime/enum.Strategy.html) 31and 32[`wasmtime::Config::strategy`](https://docs.rs/wasmtime/latest/wasmtime/struct.Config.html#method.strategy) 33for more details. 34 35## Enable Parallel Compilation 36 37Wasmtime can compile Wasm programs in parallel, speeding up the compilation 38process more or less depending on how many cores your machine has and the exact 39shape of the Wasm program. Wasmtime will generally enable parallel compilation 40by default, but it does depend on the host platform and cargo features enabled 41when building Wasmtime itself. You can double check that parallel compilation is 42enabled via the setting the 43[`wasmtime::Config::parallel_compilation`](https://docs.rs/wasmtime/latest/wasmtime/struct.Config.html#method.parallel_compilation) 44configuration option. 45 46## Putting It All Together 47 48```rust,ignore 49{{#include ../examples/fast_compilation.rs}} 50``` 51 52## See Also 53 54* [Pre-Compiling Wasm Programs](./examples-pre-compiling-wasm.md) 55* [Tuning Wasmtime for Fast Wasm Instantiation](./examples-fast-instantiation.md) 56* [Tuning Wasmtime for Fast Wasm Execution](./examples-fast-execution.md) 57