Skip to content

Transport Layer Performance Improvements #2226

@iduartgomez

Description

@iduartgomez

Transport Layer Performance Improvements

Background

PR #2224 added performance benchmarks and analysis for the transport layer. This issue tracks implementing the identified optimizations.

Benchmark Results Summary

Component Time % of Packet Path
UDP syscall (send) 12.7µs 70%
Serialization 3.82µs 21%
AES-GCM encryption 1.14µs 6%
Nonce generation 34.7ns <1%

Key finding: Channel buffer size of 1 vs 100 showed 27x throughput difference.

Proposed Improvements

High Priority (Low Effort)

  • Increase channel buffer sizes - Change channel(1) to channel(64) or higher in packet routing paths. This is the highest-impact, lowest-risk change.

  • Switch to counter-based nonces - Replace rand::random() nonce generation with atomic counter + connection ID. 5.5x faster (34.7ns → 6.3ns).

Medium Priority (Medium Effort)

  • Implement syscall batching - Use sendmmsg/recvmmsg to batch multiple packets per syscall. Potential 5-10x improvement in packet throughput. Requires platform-specific code paths.

  • Pre-allocate packet buffers - Pool packet buffers instead of allocating per-packet to reduce allocation overhead.

Lower Priority (Higher Effort)

  • Evaluate zero-copy paths - Investigate bytes::Bytes or similar for avoiding copies between encryption and send.

  • Alternative serialization - Benchmark rkyv or postcard as bincode alternatives (serialization is 21% of packet creation).

Running Benchmarks

cargo bench --bench transport_perf --no-default-features --features "redb,websocket"

# Or specific levels
cargo bench --bench transport_perf -- level0  # Pure computation
cargo bench --bench transport_perf -- level1  # Mock I/O (channel tests)
cargo bench --bench transport_perf -- level2  # Real sockets

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-networkingArea: Networking, ring protocol, peer discoveryE-mediumExperience needed to fix/implement: Medium / intermediateT-enhancementType: Improvement to existing functionality

    Type

    No type

    Projects

    Status

    Triage

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions