Avoid duplicate peer snapshot size serialization

Closed
TE
6d ago
+258-8

HOLD: Investigating the measured CPU increase with a paired base/head run on one worker before landing.

Peer snapshot eviction and replacement serialized each removed record twice. They now compute its serialized size once. Size calculation uses a counting writer instead of allocating a Vec. Coverage, ordering, eviction and disk limits remain unchanged; retained and queued limits remain 16 MiB of serialized bytes, not heap.

Leo's words (2026-10-28): "And especially, like, say, you know, how much RAM, how many CPU cores are we taking with all these things? Are there ways to make things more efficient? Like these are all things that are under our umbrella that we need to do, and we need to do really, really fucking well."

Validation:

  • Base allocation regression RED: 40786236156, job d46e3ecfbf1345138c2bd2716972483e: record_bytes allocated 1 times, expected zero. Identical new tests copied onto base.
  • Head compilation, 43 store tests and six daemon measurement cases GREEN: 40786203182, job 5ed2e5b51b934e8fac4b69a2aea81246.
  • The broader disk/read/store test selection, including the head allocation regression, is dispatched in 40787019455.
  • Independent Codex gpt-6-astra high/fast SHIP at 1d96c98741acb321fbb4617654ac8b1b66776891.

Performance

Base 1f0f687b2f32a9f506e19e7f683e8362fd3da6b2; fix 1d96c98741acb321fbb4617654ac8b1b66776891. Identical hermetic daemon_memory::peer_snapshot_cache_saturation_cost_with_object_heavy_payloads on 16-vCPU Linux: ten fixed remote sessions × 400 nested-object records, two attach/read passes, plus N retained idle or closed local sessions. Measurements count the receiving daemon alone. All six cases verify actual cached records and last sequence.

metricbeforeafterdeltaharness or run link
idle, N=0: RSS KiB78136884146460096 (7.7%)base / head
idle, N=0: peak RSS KiB79520884146446256 (5.8%)base / head
idle, N=0: CPU ms9400155706170 (65.6%)base / head
idle, N=288: RSS KiB85871692080462088 (7.2%)base / head
idle, N=288: peak RSS KiB87357292080447232 (5.4%)base / head
idle, N=288: CPU ms8790140705280 (60.1%)base / head
idle, N=1000: RSS KiB996204105398057776 (5.8%)base / head
idle, N=1000: peak RSS KiB1014208105398039772 (3.9%)base / head
idle, N=1000: CPU ms9120149205800 (63.6%)base / head
closed, N=0: RSS KiB909660811176-98484 (-10.8%)base / head
closed, N=0: peak RSS KiB929124811176-117948 (-12.7%)base / head
closed, N=0: CPU ms9290135104220 (45.4%)base / head
closed, N=288: RSS KiB8426161043932201316 (23.9%)base / head
closed, N=288: peak RSS KiB8536641043932190268 (22.3%)base / head
closed, N=288: CPU ms9780152805500 (56.2%)base / head
closed, N=1000: RSS KiB1166752119198825236 (2.2%)base / head
closed, N=1000: peak RSS KiB1179692119198812296 (1.0%)base / head
closed, N=1000: CPU ms8810138505040 (57.2%)base / head

These first measurements do not establish an overall performance improvement: CPU rises and RSS varies. A paired same-worker run 40787169549 is checking that signal. The allocation test proves removal of the temporary serialization buffer, but object-heavy JSON still amplifies substantially in heap. No new heap limit is asserted from a serialized-byte budget. No timers added; both fixture daemons are reaped.

Duplicate searches found no matching sizing fix. pr-overlap was attempted but its request form was rejected by the broker.

Agent session: agent session