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. #3773

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
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
8 changes: 8 additions & 0 deletions posting/list.go
Original file line number Diff line number Diff line change
Expand Up @@ -401,11 +401,19 @@ var postingPool = &sync.Pool{
},
}

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

func (l *List) Release() {
fromList := func(list *pb.PostingList) {
for _, p := range list.GetPostings() {
postingPool.Put(p)
}
list.Reset()
postingListPool.Put(list)
}
fromList(l.plist)
for _, plist := range l.mutationMap {
Expand Down
2 changes: 1 addition & 1 deletion posting/lists.go
Original file line number Diff line number Diff line change
Expand Up @@ -241,7 +241,7 @@ func (lc *LocalCache) getInternal(key []byte, readFromDisk bool) (*List, error)
pl = &List{
key: key,
mutationMap: make(map[uint64]*pb.PostingList),
plist: new(pb.PostingList),
plist: postingListPool.Get().(*pb.PostingList),
}
}

Expand Down
4 changes: 2 additions & 2 deletions posting/mvcc.go
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ func ReadPostingList(key []byte, it *badger.Iterator) (*List, error) {
l := new(List)
l.key = key
l.mutationMap = make(map[uint64]*pb.PostingList)
l.plist = new(pb.PostingList)
l.plist = postingListPool.Get().(*pb.PostingList)

// Iterates from highest Ts to lowest Ts
for it.Valid() {
Expand Down Expand Up @@ -172,7 +172,7 @@ func ReadPostingList(key []byte, it *badger.Iterator) (*List, error) {
return l, nil
case BitDeltaPosting:
err := item.Value(func(val []byte) error {
pl := &pb.PostingList{}
pl := postingListPool.Get().(*pb.PostingList)
x.Check(pl.Unmarshal(val))
pl.CommitTs = item.Version()
for _, mpost := range pl.Postings {
Expand Down