Four-entry inline metadata cache candidate

Status: isolated candidate against d8635bf, with accepted benchmark 005041 as the comparison baseline. Production integration and IC measurements are pending. This experiment changes shared transient cache representation, not persisted metadata or collection APIs.

Hypothesis

InlineCache currently keeps one admission inline and sends every further entry to a BTreeMap. An ordinary actor scope admits its catalog, module memory and collection, so a small working set can allocate a tree node before the actual collection operation. The candidate keeps four entries inline and retains the existing lazy ordered spill for larger working sets. Reads of those first four entries require no cache allocation.

The same private cache type serves descriptors, allocation admissions, object admissions, metadata locations and private-pool lookup. Exact keys, existing 64/128-entry limits, scope lifetimes, descriptor validation and mutation invalidation are unchanged. Only immutable metadata locations remain cached across messages. No payload, native reference or mutable descriptor admission crosses its original validity boundary.

Four admissions stay pinned while spill entries exist, versus one in the current implementation. Eviction removes the smallest spill key; once the spill is empty, it removes the last occupied inline slot. Removing an inline key promotes the smallest spill entry. Thus a nonempty spill always implies a full inline prefix, which prevents duplicate keys after vacancies and permits inserting into a vacant slot without another spill lookup. This is a deliberate eviction-policy change as well as an allocation change; measurements cannot attribute all differences to avoided heap allocation alone.

Native footprint control

An approved standalone pinned-Rust probe copies exact type field definitions from d8635bf and the candidate. It omits methods and unrelated derives, and records compiler and source hashes beside footprint.rs and footprint.csv. These are native size_of values, not measured Wasm stack frames or IC page charges.

Type/value Current bytes Candidate bytes Increase
Descriptor cache 336 1,272 936
Read allocation cache 208 760 552
Write allocation cache 96 312 216
Object admission cache 104 344 240
ReadCache 648 2,376 1,728
Read<VecMemory> 704 2,432 1,728
Write<VecMemory> 704 2,216 1,512
Store<VecMemory> 184 328 144

The complete decoded descriptor is 280 bytes and allocation header state is 136 bytes in this native layout. Four inline entries substantially increase scope storage. The compiler may initialize only option tags, or move larger aggregates; only emitted Wasm and IC measurements establish those costs. Empty and sparse calls, small maps, traversal, mutation and all placements are necessary controls.

The probe can be reproduced from the repository root by sourcing ver1/tools/env.sh, compiling footprint.rs with $RUSTC --edition 2024 -O, and running its ignored .bin output. It does not use Cargo or a shared build target.

Checks

inline-four.patch contains the private cache replacement and its unit tests. The tests cover the allocation-free prefix, spill promotion and replacement, and deterministic mixed insert/update/remove/eviction against an ordinary exact-key map. Eviction victims are intentionally not assumed to match a sorted map.

inline-four-tests.patch adds cache_pressure.rs. It keeps an outer payload borrow while admitting 144 resources and blocks, crossing the inline/spill boundary and both cache limits; direct retained and copying stable backings run through immutable and mutable scopes. Free/reuse and retirement/resource-slot reuse are checked for early inline, evicted and still-spilled admissions. Old identities must remain invalid after allocator reuse. Tests retain all existing runtime authority checks and require no production instrumentation.