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

Use sync.Pool for posting lists in getInternal and getNew #3829

Closed
wants to merge 1 commit into from

Conversation

martinmr
Copy link
Contributor

@martinmr martinmr commented Aug 16, 2019

This change is Reviewable

@martinmr martinmr requested a review from manishrjain as a code owner August 16, 2019 19:04
Copy link

@pullrequest pullrequest bot left a comment

Choose a reason for hiding this comment

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

✅ A review job has been created and sent to the PullRequest network.


@martinmr you can click here to see the review status or cancel the code review job.

Copy link

@pullrequest pullrequest bot left a comment

Choose a reason for hiding this comment

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

1 Message
The description of this pull request is blank. Adding a high-level summary will help our reviewers provide better feedback.

@martinmr
Copy link
Contributor Author

Previous PR: #3773. The base branch is deleted so I couldn't reopen it.

@danielmai could you see if there's a difference in your machine. I've been using the 1 million dataset.

Copy link

@pullrequest pullrequest bot left a comment

Choose a reason for hiding this comment

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

This looks like it matches the description and uses the sync.Pool for those two methods. It looks like there are a good many other places that allocate new PostingLists too but I'm guessing that is out of scope or not as important at this point in time to update those to use the pool.


Reviewed with ❤️ by PullRequest

Copy link

@pullrequest pullrequest bot left a comment

Choose a reason for hiding this comment

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

I think the sync.Pool is a great tool and I only had a minor comment. My primary concern with its use is the caveat in the docs for when this would be appropriate.

On the other hand, a free list maintained as part of a short-lived object is not a suitable use for a Pool, since the overhead does not amortize well in that scenario. It is more efficient to have such objects implement their own free list.

Source: https://golang.org/pkg/sync/#Pool

That leads me to wonder why you arrived at this as a bottleneck in functions sending the pb message? Have you conducted any microbenchmarks (I can't see them in this PR unfortunately).

Just want to raise the flag that the back pressure you are solving for may be in other parts of the codebase.

In general it appears that the longer the expected lifespan of pl the more appropriate the use of this pool.


Reviewed with ❤️ by PullRequest

@@ -402,11 +402,19 @@ var postingPool = &sync.Pool{
},
}

var postingListPool = &sync.Pool{
New: func() interface{} {
return &pb.PostingList{}
Copy link

Choose a reason for hiding this comment

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

Since a posting list is not a pointer on instantiation, I would opt for this method to be consistent with the Go Standard Library:

return new(pb.PostingList)

There is a talk by Bill Kennedy that differentiates between value semantics and is why I raise the issue.

Copy link

@pullrequest pullrequest bot left a comment

Choose a reason for hiding this comment

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

✖️ This code review was cancelled. See Details

@martinmr martinmr force-pushed the martinmr/reuse-posting-lists branch from 3c68d9c to f38851d Compare September 3, 2019 18:40
@martinmr
Copy link
Contributor Author

martinmr commented Sep 3, 2019

Closing this PR for now. There were some other issues with calling release (#3885 for example) so release is not being called anymore.

@martinmr martinmr closed this Sep 3, 2019
@joshua-goldstein joshua-goldstein deleted the martinmr/reuse-posting-lists branch August 19, 2022 00:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

1 participant