perf: tighten network timeouts for faster connections#38
Merged
Conversation
…ck-methods refactor: remove dead connect_dual_stack and try_connect_family methods
Tests were using ConnectionHealth enum and connection_health() method that were removed from PeerConnection/Node. Rewrote health tests to use is_connected() and removed stale health ping/pong fields from struct literals. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
…-health-refs fix: remove references to deleted ConnectionHealth API in tests
Reduce connection strategy timeouts based on RTT analysis (300ms worst-case cross-globe RTT). The previous values were overly conservative, causing up to 89s worst-case connection time to unreachable peers. Changes: - Direct connection: 5s → 2s (1-2 RTTs + margin) - Hole-punch round: 15s → 3s (3 RTTs + margin) - Max hole-punch rounds: 3 → 2 - Relay establishment: 30s → 10s - Post-hole-punch direct retry: 3s → 1s (warm NAT pinhole) - Default send ACK timeout: 1s → 500ms - Remove redundant hardcoded 15s deadline in try_hole_punch; outer strategy.holepunch_timeout() is now the single source of truth Worst-case connection path drops from 89s to ~21s. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Contributor
Benchmark ResultsPerformance Comparison
SummaryConfiguration
|
After lowering DEFAULT_SEND_ACK_TIMEOUT to 500ms, both constants held the same value, making TimeoutConfig::fast() identical to default for send_ack_timeout. Lower the fast variant to 250ms to match the halved-interval pattern used throughout the fast profile. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
jacderida
approved these changes
Apr 4, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
try_hole_punch; the outerstrategy.holepunch_timeout()is now the single source of truthTimeout changes
ipv4_timeoutipv6_timeoutholepunch_timeoutrelay_timeoutmax_holepunch_roundsPOST_HOLEPUNCH_DIRECT_RETRY_TIMEOUTDEFAULT_SEND_ACK_TIMEOUTTest plan
cargo test --lib connection_strategy— 16 passedcargo test --lib happy_eyeballs— 15 passedcargo fmt --all -- --check— cleancargo clippy --all-targets --all-features -- -D warnings— clean🤖 Generated with Claude Code
Greptile Summary
This PR tightens all NAT traversal timeouts (direct: 5s→2s, hole-punch: 15s→3s, relay: 30s→10s, max rounds: 3→2) and removes the redundant hardcoded 15s deadline inside
try_hole_punch, makingstrategy.holepunch_timeout()the single source of truth. The worst-case connection path drops from ~89s to ~21s.Confidence Score: 5/5
Safe to merge — all findings are P2 style/cleanup and do not affect correctness.
The timeout reductions are well-reasoned with a clear RTT-based rationale, unit tests pass, and the removal of the duplicate internal deadline in
try_hole_punchis a clean simplification. The only issue isFAST_SEND_ACK_TIMEOUTbeing a now-identical copy ofDEFAULT_SEND_ACK_TIMEOUT, which is a minor dead-code concern with no runtime impact.src/config/nat_timeouts.rs—FAST_SEND_ACK_TIMEOUTshould be differentiated fromDEFAULT_SEND_ACK_TIMEOUTor removed.Important Files Changed
DEFAULT_SEND_ACK_TIMEOUT1s→500ms;FAST_SEND_ACK_TIMEOUTis now an identical dead duplicate at 500ms.try_hole_punch;POST_HOLEPUNCH_DIRECT_RETRY_TIMEOUTreduced 3s→1s; outerstrategy.holepunch_timeout()is now the single source of truth.Sequence Diagram
sequenceDiagram participant C as Caller participant S as ConnectionStrategy participant E as P2pEndpoint participant Coord as Coordinator participant T as Target C->>S: new(StrategyConfig::default()) note over S: DirectIPv4 stage C->>E: connect(target_ipv4) note over E: timeout = 2s (was 5s) E-->>C: Err (timeout) C->>S: transition_to_ipv6() C->>E: connect(target_ipv6) note over E: timeout = 2s (was 5s) E-->>C: Err (timeout) C->>S: transition_to_holepunch() loop max 2 rounds (was 3) C->>E: try_hole_punch(target, coordinator) note over E: outer timeout = 3s (was 15s) E->>Coord: initiate_nat_traversal / PUNCH_ME_NOW Coord->>T: relay PUNCH_ME_NOW T->>E: QUIC handshake (PQC ML-KEM-768) alt connection detected E-->>C: Ok(PeerConnection) else timeout or error C->>E: connect(target) note over E: POST_HOLEPUNCH_DIRECT_RETRY = 1s (was 3s) E-->>C: Ok or Err S->>S: increment_round / transition_to_relay end end C->>E: try_relay_connection(target, relay) note over E: relay_timeout = 10s (was 30s) E-->>C: Ok(PeerConnection) or Err note over C,T: Worst-case: 2+2+3+1+3+1+10 ≈ 22s (was ~89s)Prompt To Fix All With AI
Reviews (1): Last reviewed commit: "perf: tighten network timeouts for faste..." | Re-trigger Greptile