Skip to content
This repository has been archived by the owner on Feb 1, 2023. It is now read-only.

Improve peer manager performance #395

Merged
merged 3 commits into from
May 21, 2020
Merged

Improve peer manager performance #395

merged 3 commits into from
May 21, 2020

Conversation

dirkmc
Copy link
Contributor

@dirkmc dirkmc commented May 19, 2020

Fixes #392

Roughly 4x improvement with a somewhat contrived benchmark:

$ go test ./internal/peermanager -run xyz -v -bench . -benchtime 5s
goos: darwin
goarch: amd64
pkg: github.com/ipfs/go-bitswap/internal/peermanager
BenchmarkPeerManager
BenchmarkPeerManager-8   	   40218	    148840 ns/op

$ go test ./internal/peermanager -run xyz -v -bench . -benchtime 5s
cpu.out
goos: darwin
goarch: amd64
pkg: github.com/ipfs/go-bitswap/internal/peermanager
BenchmarkPeerManager
BenchmarkPeerManager-8   	  182610	     33038 ns/op

// Send cancels to a particular peer
send := func(p peer.ID, pws *peerWant) {
// Include broadcast cancels
peerCancels := append(cancelsBuff[:0], broadcastKs...)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: you don't have to copy these every time.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You're right, good idea 💡 I updated the benchmark stats above

@dirkmc dirkmc requested a review from Stebalien May 20, 2020 14:32
// Send cancels to a particular peer
send := func(p peer.ID, pws *peerWant) {
// Start the index into the buffer after the broadcast wants
i = broadcastKsCount
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
i = broadcastKsCount
i := broadcastKsCount

@Stebalien
Copy link
Member

#399

Instead of tracking offsets, just create a "new" slice starting with the
broadcast cancel slice. Under the covers, this will just use the same memory
over and over.
@Stebalien Stebalien merged commit 0730042 into master May 21, 2020
@Stebalien Stebalien mentioned this pull request May 26, 2020
77 tasks
Jorropo pushed a commit to Jorropo/go-libipfs that referenced this pull request Jan 26, 2023
Improve peer manager performance

This commit was moved from ipfs/go-bitswap@0730042
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Slowness from prepareWantHaves
2 participants