Skip to main content

Module autoload_cache

Module autoload_cache 

Source
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::autoloads SQLite row tracks the source file/offset/size. Rebuild logic relies on compinit clearing the whole rkyv shard at recompute time (see AutoloadShardWriter — 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§

ArchivedAutoloadEntry
An archived AutoloadEntry
ArchivedAutoloadShard
An archived AutoloadShard
ArchivedShardHeader
An archived ShardHeader
AutoloadCache
AutoloadEntry
AutoloadEntryResolver
The resolver for an archived AutoloadEntry
AutoloadShard
AutoloadShardResolver
The resolver for an archived AutoloadShard
MmappedShard
ShardHeader
ShardHeaderResolver
The resolver for an archived ShardHeader

Constants§

SHARD_FORMAT_VERSION
SHARD_MAGIC
“ZRAL” little-endian.

Statics§

CACHE

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 the entries HashMap and writes the shard exactly once.
try_save_one