Remove redundant offset-array opens in the Rust writer
Stacked on #16. Merge order: #13, #14, #15, #16, then this. Completes SOW-0137 (.agents/sow/done/SOW-0137-20260726-rust-writer-residual-array-open-performance.md).
Decisions for review (all agent-chosen; internal only, no byte or API change)
- C1, taken: the global ENTRY-array append opens the tail array mutably once to read its capacity and write the slot, instead of a read-only open followed by a mutable open.
- C2, taken: the regular DATA-array link keeps the tail capacity the chain walk already read, instead of reopening the tail.
- C3, taken (after review): a new entry array gets slot 0 written at allocation, instead of being reopened. The first rejection was wrong: every new DATA object allocates an array, so mixed workloads hit this 34,157 times per 20,000 rows. Entry-array HMACs cover only the object header, so sealing is unchanged.
- Not taken: regular-format DATA links still walk the array chain from the head. That is systemd's own regular-format algorithm, and removing it would need a new in-memory tail cache.
Mutable opens run the same type, size and bounds checks as read-only ones. Publication order is unchanged.
Measurement
Callgrind instructions at 20,000 rows, before → C1+C2 → C1+C2+C3:
| Format | Workload | Before | C1+C2 | +C3 |
|---|---|---|---|---|
| compact | netflow | 2119.1M | 2114.3M (−0.2%) | 2113.1M (−0.06%) |
| compact | mixed | 3060.1M | 3054.8M (−0.2%) | 3041.5M (−0.44%) |
| regular | netflow | 3980.7M | 3777.0M (−5.1%) | 3775.7M (−0.03%) |
| regular | mixed | 3940.6M | 3788.4M (−3.9%) | 3774.9M (−0.36%) |
Release timing, baseline vs C1+C2+C3, regular format, 20 ABBA pairs per workload at host load 36-41: mixed +3.7% median (faster in 19/20 pairs), netflow +12.1% (19/20). The host was loaded, so timing is secondary evidence; an earlier -1.4% mixed run is not reproduced but remains unexplained.
Validation
- Output is byte-identical to the baseline in all four configurations, with and without C3.
- Stock
journalctl --verifypasses all four outputs. cargo test --workspacepasses.- Live matrix (go, rust and stock readers × regular, zstd, compact, sealed): 8/8.
Summary by cubic
Removes redundant offset-array opens in the Rust writer so regular-format writes execute 3.9-5.1% fewer instructions with byte-identical output. Completes SOW-0137.
- The ENTRY-array append now opens the tail array mutably once instead of read-only then mutable.
- The regular DATA-array link keeps the tail capacity the chain walk already read instead of reopening it.
- Newly allocated entry arrays write slot 0 through the allocation guard, removing the reopen that followed each allocation.
- Mutable opens run the same type, size, and bounds checks as read-only ones; publication order is unchanged.
- Output is byte-identical in all four benchmark configurations,
journalctl --verifypasses, and the live reader matrix passes 8/8.