-
-
Notifications
You must be signed in to change notification settings - Fork 108
Description
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)tochannel(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/recvmmsgto 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::Bytesor similar for avoiding copies between encryption and send. -
Alternative serialization - Benchmark
rkyvorpostcardas 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 socketsMetadata
Metadata
Assignees
Labels
Type
Projects
Status