Skip to content

transport and messaging perf review #4241

@Basedfloppa

Description

@Basedfloppa

1 - Bytes for payloads: make operation clones O(1)

Location: crates/core/src/message.rs, crates/core/src/operations/

Problem: Operation messages (PutMsg, GetMsg, SubscribeMsg) carry contract state as Vec<u8>. Cloning an operation (per hop in relay chain) deep-copies the entire payload — full alloc + memcpy. For 500 KB state: ~500 µs + 500 KB alloc per clone.

Fix: Replace Vec<u8> with bytes::Bytes (already a dep). Bytes::clone() is an atomic refcount increment (~0.1 µs). Requires #[serde(with = "bytes::serde")] on fields.

Gain: Clone 500 KB: ~500 µs → ~0.1 µs (~5000×). Forward to 3 peers: 1.5 MB alloc → 3 refcount bumps.

Effort: High (architectural, days). Coordinate with in-flight PRs.


2 — Congestion window busy-poll: replace with tokio::sync::Notify

Location: crates/core/src/transport/peer_connection/outbound_stream.rs:132-194

Problem: When BBR congestion window is full, send task busy-polls: 10× yield_now() (immediate re-queue), then 100 µs sleep, then 1 ms sleep. Under congestion at 1 Mbps: 7–30 ms/s CPU burned in polling.

Fix: Add tokio::sync::Notify to congestion controller. ACK path calls notify_one(), sender calls notified().await. Zero polling, instant wakeup.

Gain: Under congestion: 7–30 ms/s CPU → ~0 ms/s. Light load: unchanged.

Effort: Medium (2–3 hr). Wire notify_one() into ACK path. No new deps.

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-contractsArea: Contract runtime, SDK, and executionA-networkingArea: Networking, ring protocol, peer discoveryE-hardExperience needed to fix/implement: Hard / a lotT-enhancementType: Improvement to existing functionality

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions