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

Remove a lot of allocations, and fix some ambiguous naming #30

Merged
merged 2 commits into from
Apr 10, 2019

Conversation

anacrolix
Copy link
Contributor

I tidied up some ambiguous behaviours after #29. In particular there's some manual copying that isn't necessary, and the user of []*peerDistance when []peerDistance will suffice (and the last change here was an attempt to reduce allocations). Copying is replaced with append to make it clear about how to preallocate, and that the slice can/will be modified in place per normal append semantics.

I see that with unusual count values given to NearestPeers, behaviour isn't optimal, but I'm guessing that's not come up as count is likely KValue which is approximately the bucket size most of the time.

SortClosestPeers isn't used anywhere that I can see. I wonder if it should even be in this repo.

@ghost ghost assigned anacrolix Apr 9, 2019
@ghost ghost added the status/in-progress In progress label Apr 9, 2019
@anacrolix anacrolix requested a review from Stebalien April 9, 2019 05:36
@anacrolix
Copy link
Contributor Author

@monotone any thoughts?

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.

Looks like good savings on allocations.

sorting.go Outdated Show resolved Hide resolved
Additionally, there it may require less allocations to pack the interface value to sort.Sort now, and lint warning about modifying a receiver in peerDistanceSorter.appendPeersFromList goes away.
@monotone
Copy link
Contributor

I think it’s pretty good now, it’s much clearer than before. thanks @anacrolix

@Stebalien Stebalien merged commit 054435f into master Apr 10, 2019
@Stebalien Stebalien deleted the rework-nearest-peers branch April 10, 2019 07:30
@ghost ghost removed the status/in-progress In progress label Apr 10, 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.

3 participants