Expand description
rkyv-backed bytecode cache for autoload functions.
Single-file shard at ~/.cache/zshrs/autoloads.rkyv. Keyed by function name
(not file path) — autoload bytecode is identified by the resolved function
name, regardless of which fpath dir or .zwc archive it came from.
Storage layout (rkyv archived):
AutoloadShard {
header: { magic, format_version, zshrs_version, pointer_width, built_at_secs },
entries: HashMap<function_name, AutoloadEntry>,
}
AutoloadEntry { binary_mtime_at_cache, cached_at_secs, chunk_blob: Vec<u8> }
Inner chunk_blob is bincode-encoded fusevm::Chunk (same constraint as
script_cache module — fusevm::Chunk is upstream and only derives serde).
Invalidation:
- zshrs binary mtime newer than
binary_mtime_at_cache⇒ entry stale (any zshrs rebuild silently invalidates the whole shard). - There is no per-source-file mtime check here. Autoload bodies live in
fpath dirs / .zwc archives and the existing
compsys::cache::autoloadsSQLite row tracks the source file/offset/size. Rebuild logic relies oncompinitclearing the whole rkyv shard at recompute time (seeAutoloadShardWriter— used by the compinit bulk-prewarm path).
Bulk-write: compinit prewarms 16k+ autoload bytecodes in one go. Per-batch
shard rewrites (the SQLite-era pattern) would re-serialize 16k entries
160 times. Instead the new API exposes AutoloadShardWriter: accumulate
all (name, blob) pairs in memory, then commit() writes the shard once.
The single-add try_save_one path remains for the cold-start case where
one autoload at a time is compiled by the interactive shell.
The on-disk shape mirrors ScriptShard — same header,
same magic-version-pointer_width discipline, same atomic-rename writes.
Structs§
- Archived
Autoload Entry - An archived
AutoloadEntry - Archived
Autoload Shard - An archived
AutoloadShard - Archived
Shard Header - An archived
ShardHeader - Autoload
Cache - Autoload
Entry - Autoload
Entry Resolver - The resolver for an archived
AutoloadEntry - Autoload
Shard - Autoload
Shard Resolver - The resolver for an archived
AutoloadShard - Mmapped
Shard - Shard
Header - Shard
Header Resolver - The resolver for an archived
ShardHeader
Constants§
- SHARD_
FORMAT_ VERSION - SHARD_
MAGIC - “ZRAL” little-endian.
Statics§
Functions§
- cache_
enabled - cached_
names - clear
- default_
cache_ path - entry_
count - stats
- try_
load - try_
merge_ in - Merge new entries into the existing shard. Use this from the compinit BACKFILL path (existing shard has most entries, just adding the missing ones).
- try_
replace_ all - Replace the entire autoload shard with the given entries. Use this from
compinit’s bulk pre-warm path — accumulates all
(name, chunk_blob)in theentriesHashMap and writes the shard exactly once. - try_
save_ one