Group allocation handoff experiment

Status: measured exploratory candidate, shortlisted as a small shared cleanup. See RESULTS.md for exact native deltas and IC screen limits. Baseline is acbb2d7; the exact revision and file hashes are in manifest.json.

candidate.patch changes only Store's allocation implementation. baseline/ and candidate/ contain the two affected source files for review and replay. The patch applies to the baseline with git apply candidate.patch; build and benchmark coordination belongs to the measurement owner. No alternate allocator or configuration branch is added to production.

Hypothesis

Grouped allocation currently searches its free heads and then repeats the same search inside take_free_chunk. When refilling a group, it also publishes a newly detached shared extent into the group free list and immediately removes that same extent before splitting it. Those intermediate reads and writes do not contribute to the final allocation or free-list state.

The candidate reuses the selected buddy order. For a refill, it splits the already detached extent directly, linking only unused siblings into the group. This should reduce shared metadata operations for any collection using groups; the effect on IC instruction charging must be measured separately.

Preserved invariants

  • The source free-list extent is still validated and removed before use.
  • Only free-list heads found by the immediately preceding scan enter the known-order helper; no intervening free-list mutation invalidates that result.
  • A shared refill is already detached and marked free. Splitting creates the same buddy states and group-owned sibling headers as the previous path.
  • Group ownership, incarnation, placement, reservation accounting, initialization, allocation-list publication and independent live-start authority are unchanged.
  • All accessible allocation bytes are initialized. There is no selective initialization, new private-memory contract, or weakened public handle check.
  • The IC supplies rollback; intermediate failure still aborts the execution.

No persisted format or public API changes. The extra internal helpers separate selection, detachment and splitting so callers can reuse facts they already established. The candidate also corrects one stale source comment referring to the previously removed free_raw function.

Qualification and comparison

Run the existing Store placement, storage-invariant and private-pool tests, plus the experiment's focused grouped-allocation diagnostic. Compare baseline and candidate backend calls/bytes with identical operations and final state. Then use unchanged ordinary Map/Set/NodeStore canisters to measure allocation and deletion workloads on both retained and stable storage. Report instruction results independently of backend-call counts; fewer calls do not guarantee fewer charged regions.

Apply tests.patch to either source version (or copy tests/group_allocation.rs to ver1/crates/cdk-rsx-store/tests/). Its hash and destination are recorded separately in manifest.json. From the repository:

source ver1/tools/env.sh
cargo test --manifest-path ver1/Cargo.toml -p cdk-rsx-store --test group_allocation -- --nocapture --test-threads=1
cargo test --manifest-path ver1/Cargo.toml -p cdk-rsx-store --test placement --test storage_invariants --test private_pool

The regression covers both placements, sibling-producing and exact-size refills, coalescing, zero initialization on reuse, stale allocation identities, group ownership, trimming and refill. The diagnostic prints reads/writes and bytes for first refill, an existing fragment and a larger refill. Counters cover complete write scopes; setup, printing and correctness reads are excluded.

alloc_in_initialized, larger private-pool policies and selectively initialized private chunks remain separate ideas. They are not part of this candidate.