@cryptotaxi247 / kubo / commits / 93151d4c3

bitswap: fewer allocations in bitswap sessions

Also, don't call time.Now in a loop. License: MIT Signed-off-by: Steven Allen <steven@stebalien.com>

Steven Allen committed Dec 5, 2017 at 10:10 UTC 93151d4c33c3cd39593429b5340b50e650002704
1 file changed +3 -2
exchange/bitswap/session.go
+3 -2
@@ -199,11 +199,12 @@ func (s *Session) run(ctx context.Context) {
199 s.cancel(keys)
200
201 case <-s.tick.C:
202 - var live []*cid.Cid
202 + live := make([]*cid.Cid, 0, len(s.liveWants))
203 + now := time.Now()
204 for c := range s.liveWants {
205 cs, _ := cid.Cast([]byte(c))
206 live = append(live, cs)
206 - s.liveWants[c] = time.Now()
207 + s.liveWants[c] = now
208 }
209
210 // Broadcast these keys to everyone we're connected to