Skip to content

Commit

Permalink
perf: don't buffer the output of FindProvidersAsync
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
Jorropo committed Sep 4, 2023
1 parent f901041 commit 68c5dee
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 10 deletions.
6 changes: 1 addition & 5 deletions fullrt/dht.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()

Expand Down
6 changes: 1 addition & 5 deletions routing.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()

Expand Down

0 comments on commit 68c5dee

Please sign in to comment.