Skip to main content

Module autoload_cache

Module autoload_cache 

Source
Expand description

autoload_cache submodule. rkyv-backed bytecode cache for autoload functions.

Single-file shard at ~/.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 crate::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
AutoloadCache — see fields for layout.
AutoloadEntry
AutoloadEntry — see fields for layout.
AutoloadEntryResolver
The resolver for an archived AutoloadEntry
AutoloadShard
AutoloadShard — see fields for layout.
AutoloadShardResolver
The resolver for an archived AutoloadShard
MmappedShard
MmappedShard — see fields for layout.
ShardHeader
ShardHeader — see fields for layout.
ShardHeaderResolver
The resolver for an archived ShardHeader

Constants§

SHARD_FORMAT_VERSION
SHARD_FORMAT_VERSION constant.
SHARD_MAGIC
“ZRAL” little-endian.

Statics§

CACHE
CACHE static.

Functions§

cache_enabled
cache_enabled — see implementation. Honors the process-local script_cache::CACHE_DISABLED AtomicBool first so parity-mode init can disable caches without exporting ZSHRS_CACHE=0 (which would otherwise leak into ${(k)parameters}).
cached_names
cached_names — see implementation.
clear
clear — see implementation.
default_cache_path
default_cache_path — see implementation.
entry_count
entry_count — see implementation.
stats
stats — see implementation.
try_load
try_load — see implementation.
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
try_save_one — see implementation.