Bounded prefix deletion candidate

This isolated candidate replaces repeated single-entry Map::clear deletion with leaf-prefix batches. It changes neither the public API, the persisted format, nor the caller's entry budget. Set::clear benefits through Map.

The base is acbb2d7, measured as benchmark 2026-10-16-234007. Candidate code has not been promoted. Apply candidate.patch to that source for testing; its hash is recorded in provenance.json. Only the measurement owner should apply it to the shared live workspace and build benchmarks.

Algorithm

Deletion's statically dispatched position selector additionally selects a count. Ordinary keyed and endpoint removals still choose one entry. Prefix clearing chooses the first leaf and drains at most:

  • min(remaining_budget, leaf_count - minimum + 1) for a nonroot leaf;
  • min(remaining_budget, leaf_count) for a root leaf.

One descent shares its leaf decode, reference-ledger reads, leaf rewrite, rebalance and metadata publication across that prefix. The returned count is subtracted from map length once. Each removed occurrence still releases its key/value references. Values are never decoded for clearing.

For the current 32-entry leaf geometry, the common sequence is one deletion from a half-full leaf, merge with its neighbor, then up to 16 deletions from the merged leaf. This is an instruction-cost hypothesis, not a measured speedup. The public budget still counts removed entries, so the existing 100,000-entry clear workload remains 98 calls at a 1,024-entry limit.

Invariant argument

Before descent, every nonroot leaf has at least its occupancy minimum. The batch leaves at least minimum - 1 entries, so its occupancy deficit is at most one. Existing single-entry rebalance therefore suffices: one borrowed sibling entry repairs the deficit, or a merge fits in the compiled leaf capacity. Merging removes at most one child from the parent; the same single-deficit argument applies recursively to branch repair. The root has no occupancy minimum and follows existing collapse/empty-root handling.

All batches descend child zero. Existing merges preserve the leftmost leaf and absorb its right sibling. This preserves the node-pool experiment's invariant that a pooled right leaf never becomes the checked root. No wholesale leftmost leaf deletion or right-sibling root promotion is introduced.

Reference ledgers are read and released before any leaf save can overwrite or free their source slab. Existing save logic gathers kept payloads before repacking, including sibling payloads during a merge. Scope finalization still owns resource retirement, allowing detach/reattach within a write scope. A zero limit never enters deletion and does not change the map revision.

Qualification

Added tests cover both placements, varied budgets around leaf boundaries, shuffled insertion topology, internal occupancy/separator correctness, reopening between calls, root collapse, reuse, and zero-limit revision stability. A reference-bearing key/value test checks both occurrences are released, refuses all value decoding, and reattaches the last child within the same scope. Existing map_bulk, map_slots, endpoint deletion and ownership tests remain necessary. Candidate measurements must include ordinary remove/take/pop cases: count propagation and Vec::drain replace part of their common internal path and may affect generated code even though their semantics do not change.

Expected focused commands, using the pinned environment:

source ver1/tools/env.sh
cargo test --manifest-path ver1/Cargo.toml -p cdk-rsx-collections prefix_clear
cargo test --manifest-path ver1/Cargo.toml -p cdk-rsx-collections --test map_bulk
cargo test --manifest-path ver1/Cargo.toml -p cdk-rsx-collections --test map_slots

No test or benchmark outcome is claimed by this initial proposal.