Expand description
rkyv-backed bytecode cache for scripts.
Single-file shard at ~/.stryke/scripts.rkyv. On 2+ runs of a given
script, lex/parse/compile is skipped — the cache hit is mmap + zero-copy
ArchivedHashMap lookup + bincode-decode of the inner Program/Chunk blobs.
Storage layout (rkyv archived):
ScriptShard {
header: { magic, format_version, stryke_version, pointer_width, built_at_secs },
entries: HashMap<canonical_path, ScriptEntry>,
}
ScriptEntry { mtime_secs, mtime_nsecs, binary_mtime_at_cache, cached_at_secs,
program_blob: Vec<u8>, chunk_blob: Vec<u8> }
Inner program_blob / chunk_blob are bincode for now — StrykeValue’s
Arc-shared graph and the CacheConst adapter aren’t trivially rkyv-archivable,
so phase 1 keeps that codec inside the rkyv outer container. Phase 2 can
derive Archive directly on Chunk / Program for true zero-copy load.
Read path:
- Lazy
mmapof the shard, kept alive for the process lifetime so repeat lookups (s test trunning 87 scripts) pay validation once. rkyv::check_archived_root::<ScriptShard>validates the byte image.- Header validated for magic / format_version / stryke_version / pointer_width.
- Per-entry: source mtime must match, and
binary_mtime_at_cache≥ running stryke binary’s mtime (any rebuild of stryke invalidates entries silently).
Write path:
flock(LOCK_EX)onscripts.rkyv.lockso concurrent writers serialize.- Read existing shard into owned form, mutate,
rkyv::to_bytes, write toscripts.rkyv.tmp.<pid>.<nanos>, fsync, atomic-rename. - Drop the in-process
mmapso the next read picks up the new shard.
Modules§
Structs§
- Archived
Script Entry - An archived
ScriptEntry - Archived
Script Shard - An archived
ScriptShard - Archived
Shard Header - An archived
ShardHeader - Cached
Script - Owned bundle handed back from
try_load/ScriptCache::get. - Mmapped
Shard - mmap + validated
*const ArchivedScriptShard. Self-referential — the pointer is valid for the lifetime of the wrapping struct. - Script
Cache - Shard cache keyed by canonical script path. One per shard file.
- Script
Entry - Script
Entry Resolver - The resolver for an archived
ScriptEntry - Script
Shard - Script
Shard Resolver - The resolver for an archived
ScriptShard - Shard
Header - Shard
Header Resolver - The resolver for an archived
ShardHeader
Constants§
- SHARD_
FORMAT_ VERSION - Bumped on incompatible rkyv schema changes.
- SHARD_
MAGIC - Magic header bytes — fail-fast if a wrong-format file is mmap’d.
Statics§
- CACHE
- Process-wide
ScriptCacherooted atdefault_cache_path().Nonewhen the cache is disabled or the path could not be opened.
Functions§
- cache_
enabled STRYKE_CACHE=0|false|nodisables the cache entirely.- clear
- Clear the global cache.
- default_
cache_ path - Default shard path:
~/.stryke/scripts.rkyv. - evict_
stale - Evict stale entries from global cache.
- file_
mtime - Get mtime from file metadata as
(secs, nsecs). - stats
- Global cache stats.
- try_
load - Try to load a cached script by source path. Returns
Noneon any miss. - try_
save - Store a compiled script in the cache.