Skip to content

perf(node,protocol): delivery loop — 1 KiB frames and a double copy per frame; the wire-breaking window closes at first deployment #1791

Closed

Description

@alpergundogdu

Group D of the serve-path hot-path audit (siblings: #1788, #1789, #1790). The steady-state per-chunk loop is already lock-free (one relaxed fetch_add for egress); its costs are frame count and copies. Two of the three items touch the wire — CLAUDE.md's pre-launch rule ("wire-breaking changes are fine") applies now and stops applying at the first public deployment, which is what makes this group time-sensitive.

1. Raise the ChunkData frame size from 1 KiB

ADR 005 fixes ChunkData at 1,024-byte chunks, so each served MiB costs 1,024 iterations of (frame validate + copy + postcard encode + QUIC write) at delivery.rs:257-277 / serve_leg.rs:178-206. The 1 MiB payment quantum (CHUNK_BYTES) and bao verification are independent of frame size — ADR 038 states wire framing boundaries are independent of chunk-group boundaries and the codec is the sole verifier — so aligning frames to the 16 KiB bao chunk group (or larger) changes no payment or verification semantics.

Fix: in-place wire change to 16 KiB+ frames, updating both sides in the same PR per pre-launch policy; update ADR 005's chunk-size text.

Improves: ≥16× fewer per-frame costs — validation, copies, allocations, QUIC write submissions — per byte served; directly raises per-core egress and lowers inter-chunk latency jitter.

Leaving as-is limits: per-node throughput ceiling is set by per-frame CPU overhead, not by NIC or disk, and the cost is permanent: after the first deployment this becomes a Tier-3 ALPN bump (cdn/client/v2) with a coordinated migration, so every serving node pays 16× frame overhead for the lifetime of v1.

2. Two full memcpys plus one heap allocation per frame

delivery.rs:265 / serve_leg.rs:186 (chunk.to_vec() out of the Bytes), then wire.rs:185 → crates/protocol/src/framing.rs:57 (postcard::to_allocvec copies the payload again into a fresh allocation), with a third touch in the ChunkFramer coalescer (delivery.rs:88-112).

Fix: encode the frame header/discriminant into a small stack/reused buffer and pass the payload Bytes through with a vectored write; restructure ChunkFramer to slice Bytes instead of copying.

Improves: near-zero-copy payload path — bytes are touched once between the store and the QUIC stream.

Leaving as-is limits: 2–3 memory touches per byte plus one allocation per frame make egress memory-bandwidth- and allocator-bound; the waste scales with concurrent streams and compounds item 1 (at 1 KiB frames it is 2,048+ copies and 1,024 allocations per MiB).

3. Batch/vector QUIC write submissions

Even with larger frames, one write_message await per frame round-trips the QUIC send machinery.

Fix: buffer several encoded frames per write, or use vectored submission. Measure after items 1–2 — they may make this moot.

Improves: fewer send-path syscalls/wakeups per byte.

Leaving as-is limits: residual per-write overhead on the highest-frequency loop in the daemon; low risk of mattering after items 1–2, which is why it ranks last.

Related: #1787–#1790.

Activity

  1. alpergundogdu commented on Aug 24, 2026

    @alpergundogdu
    ContributorAuthor

    Item 1 is superseded by #1796: instead of picking a coarser fixed frame size, ChunkData becomes variable-size at the sender's choice — non-empty at the protocol level, bounded above only by the 16 MiB MAX_MESSAGE_SIZE framing cap, with practical sizes governed by the credit window / 1 MiB payment cadence. That also delivers most of item 2 (the ChunkFramer re-chop buffer disappears; the remaining copy is the to_vec + postcard encode, still tracked here). The coarser-progress-signal trade-off this creates for stall detection is tracked in #1797. Item 3 (batched/vectored QUIC writes) stays here, to be measured after #1796 lands.


    Generated by Claude Code

  2. moved this from Backlog to Ready in deCDNon Aug 24, 2026
  3. moved this from Ready to Done in deCDNon Aug 24, 2026
  4. moved this from Done to Backlog in deCDNon Aug 25, 2026
  5. self-assigned this
    on Aug 26, 2026
  6. moved this from Backlog to In progress in deCDNon Aug 26, 2026
  7. added a commit that references this issue on Aug 26, 2026
  8. moved this from In progress to Done in deCDNon Aug 26, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Fields

Priority

None yet

Projects

  • Status
    Done

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions