Right-leaf fixed-pool candidate
Status: isolated experiment against acbb2d7; not accepted production code.
The changed source copies and candidate.patch are the candidate. The build owner
applies the patch to a controlled source snapshot, archives the inputs and Wasms,
and restores its prior source before trying another candidate. No target or
independent toolchain is kept here.
A scalar Map leaf requests 688 initialized index bytes. Ordinary allocation rounds that plus its 64-byte header to 1,024 bytes. The existing resource-owned private pool packs five such leaves into one 4,096-byte backing slab. This can amortize ordinary allocator metadata and reduce index storage, but pool controls, bitmap/list updates, ungrouped pool placement and changed physical-page positions may make individual operations slower. Measure before accepting.
Only split-right leaves use the pool, and only when at least two compiled leaf extents fit the existing slab. Wide branches remain ordinary: a 3,392-byte u64 branch would fit only one slot and gain no packing. Compact and full root allocations remain ordinary as well. Values keep their existing separate slabs; this experiment does not pool payloads or change branch/leaf algorithms.
There is no root copy or new root indirection. Every split creates a right sibling, every merge preserves the left sibling, and root collapse promotes child zero. The original ordinary leftmost leaf therefore survives until the map becomes empty. Copy/build/bulk methods all use the same insertion/deletion paths. This invariant must remain explicit when composing another rebalance or bulk-clear candidate; an algorithm that promotes the right survivor would need a new design.
Private links remain 16 bytes. Low bits zero and one select their compiled extent; bit two marks a private slot. Slots contain the real payload address, with no public generation. Slot addresses cannot escape the collection and saved cursors must pass the existing resource/revision admission before traversal. The Store's existing eight-byte slot alignment is made an explicit public constant and enforced by compile-time allocator geometry assertions. There is no new per-node check. Public roots keep ordinary checked generational admission.
All slots are fully initialized by the existing pool allocator before use. Rebalancing preserves the current retain/release and slab lifecycle rules. Empty private slabs return to the shared allocator, apart from the pool's single warm empty slab per class; ordinary resource retirement releases that too. IC rollback and scope finalization are unchanged.
The candidate bumps the Map schema to five; there is no older-layout reader or migration. It includes focused tests for front/back/alternating deletion through collapse, actual pool use/release, clear/regrowth/reopen, stale cursors, retirement, and handle-valued reference occurrence counts. Existing private-range and corrupt cursor fixtures are adapted to distinguish ordinary blocks and private slots.
Required comparisons: Map/Set/NodeStore insert (including split), lookup, delete, clear, population and allocated/private/pool-reserved memory, at 100, 10k and 100k, retained and stable. Include the multi-position 100k Map suite to avoid accepting one favorable page alignment. The root invariant and reference tests must pass before IC timing is used as evidence.
Separate unmeasured proposal: small scalar values beside their leaf
After isolating the pool effect, one possible layout experiment is a single private backing slot containing both a small fixed reference-free leaf index and its payload reserve. The encoded regions stay separate: key-only operations request only index bytes, and value operations retain exact bounded ranges. For u64 keys and values this is 688 + 256 = 944 bytes, allowing four slots in the existing pool slab, compared with 1,024 + 512 bytes of ordinary backing per leaf. That arithmetic suggests roughly 39% less leaf backing before pool metadata and occupancy effects; it is not a measured whole-Map memory reduction or speedup.
Colocation might eliminate an additional IC mapped-region access for operations that need both index and value. Its tradeoff is lower pure-index density than the five-leaf index-only pool, so key-only scans might lose some benefit. Large, variable and reference-bearing values would retain separately bounded storage. This needs a distinct link/slab representation and its own safety and benchmark review. It is not implemented by this candidate or included in its evidence.
The compiled eligibility test would require both key and value reference depth
zero, a nonzero fixed value width, and the maximum leaf index plus a complete
value reserve to fit the chosen private slot budget with useful slab occupancy.
No application allocator option is needed. The current Slab { block: BlockId, capacity } assumes an independently freed ordinary allocation; a new private
slab/range representation would need to distinguish an owned allocation from a
subrange of its leaf, including cursor and stored-entry payload links. The latter
must never be freed independently. NodeId already distinguishes pooled and
ordinary nodes; root capacity/admission and exact index-only reads would need to
remain explicit if the same coallocation policy were applied to ordinary roots.