Remove redundant offset-array opens in the Rust writer

KT
7d ago
+364-288

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:

FormatWorkloadBeforeC1+C2+C3
compactnetflow2119.1M2114.3M (−0.2%)2113.1M (−0.06%)
compactmixed3060.1M3054.8M (−0.2%)3041.5M (−0.44%)
regularnetflow3980.7M3777.0M (−5.1%)3775.7M (−0.03%)
regularmixed3940.6M3788.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 --verify passes all four outputs.
  • cargo test --workspace passes.
  • 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 --verify passes, and the live reader matrix passes 8/8.