Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refresh Cpl's, not buckets #46

Merged
merged 3 commits into from
Dec 16, 2019
Merged

Conversation

aarshkshah1992
Copy link
Contributor

@aarshkshah1992 aarshkshah1992 commented Dec 12, 2019

@aarshkshah1992 aarshkshah1992 changed the title [WIP] Refresh Cpl's, not buckets Refresh Cpl's, not buckets Dec 12, 2019
Copy link
Member

@Stebalien Stebalien left a comment

Choose a reason for hiding this comment

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

Some minor changes but otherwise lgtm.

table.go Outdated
@@ -21,6 +21,15 @@ var log = logging.Logger("table")
var ErrPeerRejectedHighLatency = errors.New("peer rejected; latency too high")
var ErrPeerRejectedNoCapacity = errors.New("peer rejected; insufficient capacity")

// MaxCplForRefresh is the maximum cpl we support for refresh.
// This limit exists because we can only generate 'MaxCplForRefresh' bit prefixes for now.
var MaxCplForRefresh uint = 15
Copy link
Member

Choose a reason for hiding this comment

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

Let's make this a constant (and private).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done.

table.go Show resolved Hide resolved
table.go Outdated
rt.tabLock.RLock()
bucketLen := len(rt.Buckets)
rt.tabLock.RUnlock()
var cpls []*CplRefresh
Copy link
Member

Choose a reason for hiding this comment

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

Let's pre-allocate this.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done.

table.go Outdated
}
// GetTrackedCplsForRefresh returns the Cpl's we are tracking for refresh.
// Caller is free to modify the returned slice as it is a defensive copy.
func (rt *RoutingTable) GetTrackedCplsForRefresh() []*CplRefresh {
Copy link
Member

Choose a reason for hiding this comment

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

nit: we can avoid a bunch of allocations by removing the pointer. That is, []CplRefresh.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done.

table.go Show resolved Hide resolved
@aarshkshah1992
Copy link
Contributor Author

aarshkshah1992 commented Dec 16, 2019

@Stebalien Have made the changes. Please take a look. Thank you ! :)

Also, if you are happy with this & merge it, please can you cut a release so we can get the changes done in Dht.

table.go Outdated
targetCpl = uint(bucketID)
i := 0
for c, t := range rt.cplRefreshedAt {
cpls[i] = CplRefresh{c, t}
Copy link
Member

Choose a reason for hiding this comment

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

cpls := make([]CplRefresh, 0, len(rt.cplRefreshedAt))
...

for ... {
  cpls = append(cpls, CplRefresh{c, t})
}

Make takes a type, length (optional), and capacity (optional). When building a slice with a known length, you can allocate with a known capacity to avoid having to re-allocate every time you run out of capacity.

See: https://blog.golang.org/go-slices-usage-and-internals

@aarshkshah1992
Copy link
Contributor Author

@Stebalien Thanks for the slice make suggestion. Have made the change. Please can you merge & cut a release if you are happy with this ?

@Stebalien Stebalien merged commit a0cac6f into libp2p:master Dec 16, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants