perf(recv): add try_recv fast path in packet receive loop#2426
Open
fanyang89 wants to merge 1 commit into
Open
perf(recv): add try_recv fast path in packet receive loop#2426fanyang89 wants to merge 1 commit into
fanyang89 wants to merge 1 commit into
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
This PR optimizes the peer packet receive hot path by adding a non-async try_recv() fast path before falling back to recv().await, aiming to reduce overhead when packets are already buffered in the channel.
Changes:
- Add
try_recv()fast path torecv_packet_from_chan()and fall back torecv().awaitonly when empty. - Inline the same
try_recv()→recv().awaitlogic inPeerManager::start_peer_recv()and remove the previous helper import.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| easytier/src/peers/peer_manager.rs | Inlines a try_recv() fast path in the main receive loop and removes the helper import. |
| easytier/src/peers/mod.rs | Updates recv_packet_from_chan() to use try_recv() first, then await recv() on empty. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Add a try_recv() fast path to recv_packet_from_chan(): if a packet is immediately available, return it without parking the task. Only when the channel is empty do we fall back to recv().await. This benefits all callers of recv_packet_from_chan() including start_peer_recv, virtual_nic, foreign_network_manager, and instance.
fanyang89
force-pushed
the
perf/recv-try-fast-path
branch
from
July 11, 2026 13:30
8093dc8 to
82b4013
Compare
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
The peer packet receive hot path (
start_peer_recv) callsrecv_packet_from_chan().awaitfor every incoming packet, which always parks the task and yields to the Tokio scheduler even when the channel already has items buffered.This adds a
try_recv()fast path: if a packet is immediately available, it is processed inline without scheduling overhead. Only when the channel is empty do we fall back torecv().await.Changes
peers/mod.rs—recv_packet_from_chan(): trytry_recv()first, fall back torecv().awaitonEmpty.peers/peer_manager.rs—start_peer_recv: inline the sametry_recv→recv().awaitpattern in the hot loop, and remove the now-unused import.Impact
~20 lines, 2 files. No behavior change — purely a fast-path optimization that avoids an unnecessary task park/wakeup cycle per packet when the channel is non-empty (the common case under load).