perf: enable wasmtime disk-backed compilation cache#8
Merged
Conversation
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).
Merging this PR will improve performance by ×2.5
Performance Changes
Comparing |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
cachefeature onstarship-runtimeandstarship-benchcreate_engine()that configuresCache::from_file(None)(platform default cache dir)Engine::default()call sites withcreate_engine()Why
plugin_loadbenchmarks at 31.1ms — 3.7x over the 8.33ms (120fps) budget. The entire cost is Cranelift recompiling the same WASM bytes from scratch on everyModule::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