From 68c5deec78217493009353a43c6e0c21f35f58f7 Mon Sep 17 00:00:00 2001 From: Jorropo Date: Fri, 25 Aug 2023 07:33:51 +0200 Subject: [PATCH] perf: don't buffer the output of FindProvidersAsync We always select it against ctx and we don't rely on the fact it will always be non blocking since when count is zero we can't realistically preallocate. Buffering use more memory makes more garbage and is less efficient than direct copies. --- fullrt/dht.go | 6 +----- routing.go | 6 +----- 2 files changed, 2 insertions(+), 10 deletions(-) diff --git a/fullrt/dht.go b/fullrt/dht.go index 60842cf3..99d1c3eb 100644 --- a/fullrt/dht.go +++ b/fullrt/dht.go @@ -1238,11 +1238,7 @@ func (dht *FullRT) FindProvidersAsync(ctx context.Context, key cid.Cid, count in return peerOut } - chSize := count - if count == 0 { - chSize = 1 - } - peerOut := make(chan peer.AddrInfo, chSize) + peerOut := make(chan peer.AddrInfo) keyMH := key.Hash() diff --git a/routing.go b/routing.go index 1a68c6eb..b0778b9d 100644 --- a/routing.go +++ b/routing.go @@ -503,11 +503,7 @@ func (dht *IpfsDHT) FindProvidersAsync(ctx context.Context, key cid.Cid, count i return peerOut } - chSize := count - if count == 0 { - chSize = 1 - } - peerOut := make(chan peer.AddrInfo, chSize) + peerOut := make(chan peer.AddrInfo) keyMH := key.Hash()