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_config_load`](https://docs.rs/wasmtime/latest/wasmtime/struct.Config.html#method.cache_config_load)
19* [`wasmtime::Config::cache_config_load_default`](https://docs.rs/wasmtime/latest/wasmtime/struct.Config.html#method.cache_config_load_default)
20* [`wasmtime::Config::disable_cache`](https://docs.rs/wasmtime/latest/wasmtime/struct.Config.html#method.disable_cache)
21* [`wasmtime::CacheStore`](https://docs.rs/wasmtime/latest/wasmtime/trait.CacheStore.html)
22
23## Enable Winch
24
25Winch is Wasmtime's "baseline" compiler: for each Wasm opcode, it emits a canned
26sequence of machine instructions to implement that opcode. This makes
27compilation fast: it performs only a single, quick pass over the Wasm
28code. However, it does not perform optimizations, so the machine code it emits
29will run Wasm programs slower than Cranelift, Wasmtime's optimizing compiler.
30
31See the API docs for
32[`wasmtime::Strategy`](https://docs.rs/wasmtime/latest/wasmtime/enum.Strategy.html)
33and
34[`wasmtime::Config::strategy`](https://docs.rs/wasmtime/latest/wasmtime/struct.Config.html#method.strategy)
35for more details.
36
37## Enable Parallel Compilation
38
39Wasmtime can compile Wasm programs in parallel, speeding up the compilation
40process more or less depending on how many cores your machine has and the exact
41shape of the Wasm program. Wasmtime will generally enable parallel compilation
42by default, but it does depend on the host platform and cargo features enabled
43when building Wasmtime itself. You can double check that parallel compilation is
44enabled via the setting the
45[`wasmtime::Config::parallel_compilation`](https://docs.rs/wasmtime/latest/wasmtime/struct.Config.html#method.parallel_compilation)
46configuration option.
47
48## Putting It All Together
49
50```rust,ignore
51{{#include ../examples/fast_compilation.rs}}
52```
53
54## See Also
55
56* [Pre-Compiling Wasm Programs](./examples-pre-compiling-wasm.md)
57* [Tuning Wasmtime for Fast Wasm Instantiation](./examples-fast-instantiation.md)
58* [Tuning Wasmtime for Fast Wasm Execution](./examples-fast-execution.md)
59