Skip to content

perf(command-bus): debounce per-send peer-registry disk load (-46% LAN RTT) - #1260

Merged
joelteply merged 3 commits into
canaryfrom
perf/airc-send-registry-debounce
Jun 20, 2026
Merged

joelteply merged 3 commits into
canaryfrom
perf/airc-send-registry-debounce

Conversation

@joelteply

Copy link
Copy Markdown
Contributor

What

Profiled the full LAN request/reply path (new seam-timing util + a latency bench). The dominant cost was not the wire — it was send_frame_to_room calling sync_account_peer_registry() on every send, which loads the peer registry from disk and re-enrols every peer. That was ~95% of the send leg (~1ms/send).

The verifier registry holds peer pubkeys for inbound verification and rarely changes between sends, so loading it per outbound message is wasted critical-path I/O. Debounced to load at most once/sec.

Result (LAN loopback, sequential RTT)

before after
total round-trip 2852µs 1531µs (−46%)
send leg 1077µs 421µs

Both command_bus_round_trip tests (LAN + relay) still pass. add_peer enrols in-memory immediately and the route-refresh tick still calls the undebounced sync, so freshness is preserved.

Also adds (reusable diagnostics — shared core lives in airc since continuum imports it)

  • airc-diagnostics::timing — opt-in seam accumulator (atomic-gated, near-zero when off), the summed twin of probe!/time_probe!.
  • Permanent opt-in send-path seams (airc.sign/append_sent/exec_route, lan.*, airc.req.*).
  • lan_latency_bench (#[ignore]) — the harness that found this + measures the next lever.

Next levers (measured)

airc.sign 113µs + airc.append_sent 107µs per send (~690µs/RTT is crypto + durability). append_sent's local durability write is backgroundable but delicate (dedup-ring/ordering) — a follow-up.

🤖 Generated with Claude Code

joelteply and others added 3 commits June 20, 2026 15:24
…N RTT)

Profiled the full LAN request/reply path with a new seam-timing util and a
latency bench. The dominant cost was NOT the wire (serialize 24us + flush 20us
+ transport 47us) — it was `send_frame_to_room` calling
`sync_account_peer_registry()` on EVERY send, which loads the peer registry
from DISK and re-enrols every peer. That was ~95% of the send leg (~1ms/send).

The verifier registry holds peer pubkeys for INBOUND verification and rarely
changes between sends, so loading it per outbound message is wasted critical-
path I/O. Debounce it: `sync_account_peer_registry_debounced` loads at most
once/sec; a burst of sends pays the disk load once. add_peer still enrols
in-memory immediately, and the route-refresh tick still calls the undebounced
sync, so freshness is preserved. LAN round-trip: 2852us -> 1531us (-46%).
Both command_bus_round_trip tests (LAN + relay) still pass.

Adds (reusable, the shared-core lives in airc since continuum imports it):
- airc-diagnostics::timing — opt-in seam accumulator (atomic-gated, near-zero
  when off), the SUMMED twin of probe!/time_probe!. Read by a bench to find
  "where did the ms go."
- send-path seams (airc.sign/append_sent/exec_route, lan.serialize/flush_ack/
  send_total, airc.req.*) — permanent opt-in observability of the send path.
- lan_latency_bench (#[ignore]) — the harness that found this + measures the
  next lever.

Remaining levers (measured, next): airc.sign 113us + airc.append_sent 107us
per send (~690us/RTT is crypto + durability). append_sent's local durability
write is backgroundable but delicate (dedup-ring/ordering) — a follow-up.

Co-Authored-By: Claude Opus 4.8 <[email protected]>
…t the frame)

Captures the design for the next latency lever after the registry-debounce fix:
per-frame Ed25519 (~113µs) is correct for the low-rate CONTROL plane (end-to-end
authenticity across relays) but a throughput killer for the high-rate STREAM
plane (WebRTC media, UDP). The fix is the standard DTLS-SRTP/QUIC/Noise pattern —
sign the session/handle ONCE (Ed25519 → X25519/HKDF), then per-frame symmetric
AEAD (ChaCha20-Poly1305), keyed off FrameKind/RouteClass. WebRTC media is already
DTLS-SRTP; bind the DTLS fingerprint → peer identity at SDP-offer. Spec only;
implementation is a coordinated transport change.

Co-Authored-By: Claude Opus 4.8 <[email protected]>
…en timing off

Adversarial review of #1260 (finding 1): the six manual `record()` seams called
`std::time::Instant::now()` UNCONDITIONALLY, so a production send with timing
disabled paid ~6 clock_gettime calls (~120ns) on the very path this PR speeds up
— self-contradictory with the perf doctrine.

Add `timing::start() -> ScopedTimer`: captures the Instant ONLY when recording is
enabled (one relaxed atomic load otherwise, no clock read), records on `.stop()`.
Convert all six await-span seams (airc.req.subscribe/send_frame, airc.append_sent/
exec_route, lan.flush_ack/send_total) to it. Disabled hot path is now truly
zero-cost; bench still prints the full breakdown; RTT unchanged (~1505µs).

Co-Authored-By: Claude Opus 4.8 <[email protected]>
@joelteply
joelteply merged commit 359af00 into canary Jun 20, 2026
6 checks passed
@joelteply
joelteply deleted the perf/airc-send-registry-debounce branch June 20, 2026 20:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant