Skip to main content

Module module_cache

Module module_cache 

Source
Expand description

A content-hash-keyed cache of compiled wasmtime::Modules.

wasmtime::Module::new measurably costs ~1.5s for a ~3.3MB module (the shared Rhai interpreter this feature adds) vs. ~125ms for a small example block — over 10x — and today nothing in this codebase caches a compiled module at all: Guest::new recompiles from scratch on every single job run. Every Script-kind node, across every spec and every job ever run against it, shares byte-identical module_bytes (the one embedded interpreter), so this cache turns an otherwise-repeated ~1.5s tax into a one-time cost per process lifetime.

Structs§

ModuleCache
Load-bearing invariant this cache does not check: every compile call through one ModuleCache must pass the same wasmtime::Engine every time. A Module is only valid for the Engine that compiled it — mixing engines through one cache would silently return a Module compiled for the wrong Engine. This codebase constructs exactly one Engine per process (cuttlefishd’s and cuttlefish build’s main), so a ModuleCache constructed once alongside it, and never shared across processes, upholds this automatically. A test that constructs its own throwaway Engine should also construct its own throwaway ModuleCache — never reuse one across two different Engines.