Packed branch mutation experiment
Status: independent source review passed; the measurement owner reports all
47 native executions passed (9 library and 38 integration). The ordinary Wasm
screen completed successfully. This is an exploratory candidate, not yet an
accepted production composition. Baseline commit:
acbb2d7b46bbf7d06575b63801cc26e57fffd836.
The first native compile caught two conflicting borrows in count/header updates.
Both were corrected by computing the count before borrowing the buffer mutably;
the preserved failure and original patch remain in the measurement artifacts.
The refrozen patch hash is
b42e6119defe0d9af6eefaf91f5741027a64ef2037c39f441a469c5c0f93574c.
The qualification directory
contains the exact measured candidate and execution evidence.
The existing packed descent already avoids decoding unchanged ancestors. A split or underflow still materializes every key in each affected branch and serializes the complete branch again. The structural replay counts 414 fully decoded branch keys for its widened-branch single deletion, against 178 in the older 32-separator tree. This models structural work; it does not attribute IC instructions or prove the entire regression's cause.
candidate.patch changes transient branch representation, keeping the existing
persisted framing and one shared insertion/rebalance algorithm:
- Fixed-width keys keep the complete encoded branch in one bounded owned buffer. Insertion/removal shift contiguous records; split and merge copy ranges; separator replacement copies only its encoded key inside that buffer.
- Variable-width keys keep encoded separator and child vectors. Branch mutations
do not need owned decoded keys; ordering decisions still use the codec's
compare_encoded, including its default decode-and-Ordimplementation. - Branch publication writes the resulting encoded buffer directly and skips the leaf-only slab read. It still publishes the complete live branch bytes. This experiment does not introduce dirty ranges or change allocator placement.
- Leaf mutation, reference accounting, slab movement and retirement are unchanged. Separator copies have no independent ownership: leaf ledgers own key references. Merges preserve the left node and free the right after gathering its data.
The fixed-width claim is the existing trusted Codec::FIXED_SIZE contract, not
a reference-free assumption. No Clone bound is added. Branch shape and capacity
stay the same; private links and root admission retain their existing proof.
Transient buffers are still allocated/copied for affected branches, so this is
not a zero-copy mutation scheme. Wider branches still cost more bytes to read and
write than narrow branches.
baseline/ and candidate/ contain only affected source files. The patch uses
repository-relative production paths and can be checked without applying it:
git apply --check research/experiments/2026-10-17-map-rebalance/candidate.patch
The measurement owner applies it in an exclusive source window, captures the source/artifact identities, then restores production after the isolated run. Do not create another target directory for this experiment.
Focused tests in the candidate:
- Two branch helper differential tests compare an independent vector model and independent encoded framing for widths 2, 8, 13, 512 and variable lengths. They cover both pop/borrow directions, replacement, every relevant split midpoint and exact append roundtrips, preserving tagged child identities.
map_packed_branchesexercises 4,096 fixed-width reference-bearing keys with reverse ordering and noClone, through internal splits, representative replacement, stale cursor rejection, reopen, merges and root collapse in both placements. Inbound counts must equal leaf entries, not separator copies.- Existing topology, Map mutation/navigation/slot/window tests cover the shared tree algorithm and unchanged generic payload movement.
The IC screen ran 548 cases across ten cohorts, one candidate trial against the three-trial baseline. Body instructions improved in 234 rows, were identical in 304, and regressed by less than 0.2% in ten. The separate matched Map point probes left lookup and miss instructions unchanged. This screen does not establish repeated candidate results or replace the full combined qualification. All 190 recorded population-memory comparisons were unchanged; these are end-of-population snapshots, not transient allocation peaks.
Selected method-body instruction counts from instructions.csv:
| NodeStore operation | Placement | Baseline | Candidate | Change |
|---|---|---|---|---|
| Insert one at 10,000 entries | Retained | 994,036 | 877,227 | −11.75% |
| Insert one at 10,000 entries | Stable | 1,167,103 | 1,053,954 | −9.69% |
| Remove 32 at 100,000 entries | Retained | 36,500,076 | 24,971,200 | −31.59% |
| Remove 32 at 100,000 entries | Stable | 35,469,217 | 24,055,464 | −32.18% |
The body interval includes scoped Store access and finalization, but excludes guards, Candid decoding/reply, verification and final IC accounting. It is not the full message's billed instruction count.
These results support reducing materialization of affected wide branches while keeping ordinary packed descent unchanged. They do not attribute the complete savings to any individual instruction or backend operation.