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

Release entryBufferPool once #5324

Merged
merged 2 commits into from
Feb 4, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 14 additions & 6 deletions pkg/iter/entry_iterator.go
Original file line number Diff line number Diff line change
Expand Up @@ -706,9 +706,8 @@ func (i *reverseEntryIterator) load() {

func (i *reverseEntryIterator) Next() bool {
i.load()
if len(i.buf.entries) == 0 {
entryBufferPool.Put(i.buf)
i.buf.entries = nil
if i.buf == nil || len(i.buf.entries) == 0 {
i.release()
return false
}
i.cur, i.buf.entries = i.buf.entries[len(i.buf.entries)-1], i.buf.entries[:len(i.buf.entries)-1]
Expand All @@ -729,12 +728,21 @@ func (i *reverseEntryIterator) StreamHash() uint64 {

func (i *reverseEntryIterator) Error() error { return nil }

func (i *reverseEntryIterator) Close() error {
func (i *reverseEntryIterator) release() {
if i.buf == nil {
return
}

if i.buf.entries != nil {
// preserve the underlying slice before releasing to pool
Copy link
Contributor

Choose a reason for hiding this comment

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

The comment is a bit weird. Should we just reslice when we get ?

Copy link
Member Author

@owen-d owen-d Feb 4, 2022

Choose a reason for hiding this comment

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

We could do this after Get'ing, yeah -- I believe that has equivalent results. The important part is that we don't nil it here because the reason we're using a pool is to preserve the underlying slice so we don't have to reallocate it. Does that make sense?

Copy link
Contributor

Choose a reason for hiding this comment

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

Yeah I would just re-slice entries are never nil.

i.buf.entries = i.buf.entries[:0]
entryBufferPool.Put(i.buf)
i.buf.entries = nil
}
entryBufferPool.Put(i.buf)
i.buf = nil
}

func (i *reverseEntryIterator) Close() error {
i.release()
if !i.loaded {
return i.iter.Close()
}
Expand Down