Expand description
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
EXTENSION — NO vendor/ COUNTERPART. rkyv-backed bytecode cache for .vim
scripts, the same architecture as awkrs/strykelang/zshrs’s script_cache.
Single-file shard at ~/.cache/vimlrs/scripts.rkyv. On the 2nd+ run of a
given script, lex/parse/compile is skipped — the cache hit is mmap +
zero-copy ArchivedHashMap lookup + a bincode-decode of the inner
fusevm::Chunk blob (the compiled program).
Storage layout (rkyv archived):
ScriptShard { header: { magic, format_version, vimlrs_version, pointer_width, built_at_secs }, entries: HashMap<canonical_path, ScriptEntry> }
ScriptEntry { mtime_secs, mtime_nsecs, binary_mtime_at_cache, cached_at_secs, chunk_blob }
Read path: lazy mmap, rkyv::check_archived_root validation, header
magic/version/pointer-width/vimlrs-version checks, then per-entry source
mtime + binary-mtime guards (any rebuild invalidates silently). Write path:
flock(LOCK_EX), read-mutate-to_bytes, fsync to a .tmp.<pid>.<nanos>,
atomic-rename. The cache format is versioned from day one so an old cached
.vim that worked yesterday never breaks (compat-floor).
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
Structs§
- Archived
Script Entry - An archived
ScriptEntry - Archived
Script Shard - An archived
ScriptShard - Archived
Shard Header - An archived
ShardHeader - Mmapped
Shard - mmap + validated
*const ArchivedScriptShard. Self-referential — the pointer is valid for the lifetime of the wrapping struct. - Script
Cache - A handle to one shard file plus its writer lock.
- Script
Entry - One cached compiled script.
- Script
Entry Resolver - The resolver for an archived
ScriptEntry - Script
Shard - The whole shard: header + path → entry map.
- Script
Shard Resolver - The resolver for an archived
ScriptShard - Shard
Header - Shard header: format identity + provenance.
- Shard
Header Resolver - The resolver for an archived
ShardHeader
Constants§
- SHARD_
FORMAT_ VERSION - Bumped on incompatible rkyv schema changes (and when the meaning of emitted builtin ids changes, e.g. the ignore-case comparison id remap).
- SHARD_
MAGIC - Magic header bytes — fail fast if a wrong-format file is mmap’d. (“VIML”)
Statics§
- CACHE
- Process-wide cache rooted at
default_cache_path;Nonewhen disabled or unopenable.
Functions§
- cache_
enabled VIMLRS_CACHE=0|false|nodisables the cache entirely.- default_
cache_ path - Default shard path:
~/.cache/vimlrs/scripts.rkyv. - file_
mtime - Source-file mtime as
(secs, nsecs). - store
- Store a compiled program for
path(best-effort; errors ignored). - try_
load - Try to load a cached
CompiledProgram(themainchunk plus any user functions) forpath.