v0.4 — KV cache tiering (hot RAM + cold SSD)#26
Merged
magicnight merged 6 commits intomainfrom Apr 18, 2026
Merged
Conversation
5 tasks: PromptCacheKey, PromptCacheStore (hot+cold LRU), engine wiring, Settings UI, CHANGELOG. MVP uses full-prompt hash; block- level longest-common-prefix matching deferred to v0.4.0.1.
Actor-based two-tier prompt cache. Hot tier is an in-memory LRU dict keyed by PromptCacheKey. Cold tier is safetensors files under `root/<shard>/<hash>.safetensors` round-tripped via mlx-swift-lm's savePromptCache / loadPromptCache. Eviction from hot persists to cold; cold hits promote back into hot. Introduces PromptCacheSnapshot — an @unchecked Sendable wrapper for [any KVCache] so snapshots can cross the actor isolation boundary (mlx-swift-lm's KVCache has no Sendable conformance). Tests cover put/get hot hit, hot->cold eviction, cold->hot restore, and miss-returns-nil. The three MLX-dependent tests skip when default.metallib is not in the test bundle (standard SPM test binaries often lack it); the miss-path test runs unconditionally.
On each generate call, hash the full input token sequence, look up a prior cache snapshot, and pass it to the token iterator so the shared prefix prefill is skipped. Save the extended snapshot after generation completes so the next turn benefits. MVP keys on exact-prefix match; vLLM-style block hashing with longest-common-prefix matching is v0.4.1+.
|
You have used all of your free Bugbot PR reviews. To receive reviews on all of your PRs, visit the Cursor dashboard to activate Pro and start your 14-day free trial. |
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
First of three v0.4.0 engine-parity sub-features (with ModelPool + MCP server to follow as separate PRs).
PromptCacheKey— sha256 hash over (modelID, tokens) with 16-way shard layoutPromptCacheStoreactor — hot dict + cold safetensors LRU,Sendablesnapshot wrapperMLXSwiftEngine.generate()wired to check store + save updated cache post-generation — HIT/MISS debug logs under `engine` categoryMVP scope
Test plan
🤖 Generated with Claude Code