Skip to content

perf: enable wasmtime disk-backed compilation cache#8

Merged
matchai merged 1 commit intomainfrom
perf/wasmtime-cache
Apr 4, 2026
Merged

perf: enable wasmtime disk-backed compilation cache#8
matchai merged 1 commit intomainfrom
perf/wasmtime-cache

Conversation

@matchai
Copy link
Copy Markdown
Member

@matchai matchai commented Apr 4, 2026

Summary

  • Enable wasmtime's built-in cache feature on starship-runtime and starship-bench
  • Add create_engine() that configures Cache::from_file(None) (platform default cache dir)
  • Replace all Engine::default() call sites with create_engine()

Why

plugin_load benchmarks at 31.1ms — 3.7x over the 8.33ms (120fps) budget. The entire cost is Cranelift recompiling the same WASM bytes from scratch on every Module::new() call. With the cache enabled, compiled machine code is persisted to disk and deserialized on subsequent loads, skipping compilation entirely.

Cache invalidation

The cache key is a SHA-256 hash of wasm bytes + compiler target + engine config + wasmtime version. It's stored under a modules/wasmtime-<VERSION>/ subdirectory, so a wasmtime upgrade automatically busts it. Writes are atomic (temp file + rename).

Expected impact

  • First load (cold cache): ~31ms (unchanged)
  • Subsequent loads (cache hit): <1ms
  • Production: Daemon restart skips compilation for unchanged plugins

Replace Engine::default() with create_engine() across all call sites.
Compiled WASM modules are now cached to the platform cache directory,
keyed on wasm bytes + engine config + wasmtime version. Subsequent
loads skip Cranelift compilation entirely (cache hit).
@matchai matchai marked this pull request as ready for review April 4, 2026 08:05
@codspeed-hq
Copy link
Copy Markdown

codspeed-hq bot commented Apr 4, 2026

Merging this PR will improve performance by ×2.5

⚡ 2 improved benchmarks
✅ 18 untouched benchmarks

Performance Changes

Mode Benchmark BASE HEAD Efficiency
WallTime plugin_load 31.1 ms 19.6 ms +58.5%
Memory plugin_load 9.5 MB 3.8 MB ×2.5

Comparing perf/wasmtime-cache (1d53f3c) with main (b7011ae)

Open in CodSpeed

@matchai matchai merged commit 2bf43de into main Apr 4, 2026
7 checks passed
@matchai matchai deleted the perf/wasmtime-cache branch April 4, 2026 08:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant