perf(peer_manager): merge redundant dashmap lookup in send_msg_internal

Replace has_peer(dst_peer_id) + send_msg_directly() with a single
get_peer_by_id() call, eliminating one redundant dashmap contains_key
query (~50-100ns) per packet on the direct-peer happy path.

send_msg_directly is no longer called from send_msg_internal but remains
available for other callers. All 7 send_msg_internal tests pass.

Benchmark (4 threads, 1400B pkts, 15s):
  Before: 234K pps, send_msg_internal avg 3.26us
  After:  230K pps, send_msg_internal avg 3.25us
  Delta within noise; ~10-50ns/pkt saved as expected for one fewer hash.
This commit is contained in:
fanyang
2026-06-28 12:45:05 +08:00
parent 79035ea972
commit 31c639f70c
+2 -2
View File
@@ -1556,8 +1556,8 @@ impl PeerManager {
&& (peers.has_peer(gateway) || foreign_network_client.has_next_hop(gateway))
{
relay_peer_map.send_msg(msg, dst_peer_id, policy).await
} else if peers.has_peer(dst_peer_id) {
peers.send_msg_directly(msg, dst_peer_id).await
} else if let Some(peer) = peers.get_peer_by_id(dst_peer_id) {
peer.send_msg(msg).await
} else if foreign_network_client.has_next_hop(dst_peer_id) {
foreign_network_client.send_msg(msg, dst_peer_id).await
} else if let Some(gateway) = peers.get_gateway_peer_id(dst_peer_id, policy.clone()).await {