scorch zap optimize via postingsList reuse
pprof graphs were showing many postingsList allocations during merging, so this change optimizes by reusing postingList memory in the merging loops.
This commit is contained in:
parent
03c8b2b7ec
commit
8c2520d55c
|
@ -34,15 +34,18 @@ type Dictionary struct {
|
|||
|
||||
// PostingsList returns the postings list for the specified term
|
||||
func (d *Dictionary) PostingsList(term string, except *roaring.Bitmap) (segment.PostingsList, error) {
|
||||
return d.postingsList([]byte(term), except)
|
||||
return d.postingsList([]byte(term), except, nil)
|
||||
}
|
||||
|
||||
func (d *Dictionary) postingsList(term []byte, except *roaring.Bitmap) (*PostingsList, error) {
|
||||
rv := &PostingsList{
|
||||
sb: d.sb,
|
||||
term: term,
|
||||
except: except,
|
||||
func (d *Dictionary) postingsList(term []byte, except *roaring.Bitmap, rv *PostingsList) (*PostingsList, error) {
|
||||
if rv == nil {
|
||||
rv = &PostingsList{}
|
||||
} else {
|
||||
*rv = PostingsList{} // clear the struct
|
||||
}
|
||||
rv.sb = d.sb
|
||||
rv.term = term
|
||||
rv.except = except
|
||||
|
||||
if d.fst != nil {
|
||||
postingsOffset, exists, err := d.fst.Get(term)
|
||||
|
|
|
@ -155,6 +155,8 @@ func persistMergedRest(segments []*Segment, drops []*roaring.Bitmap,
|
|||
var bufMaxVarintLen64 []byte = make([]byte, binary.MaxVarintLen64)
|
||||
var bufLoc []uint64
|
||||
|
||||
var postings *PostingsList
|
||||
|
||||
rv := make([]uint64, len(fieldsInv))
|
||||
fieldDvLocs := make([]uint64, len(fieldsInv))
|
||||
fieldDvLocsOffset := uint64(fieldNotUninverted)
|
||||
|
@ -231,7 +233,8 @@ func persistMergedRest(segments []*Segment, drops []*roaring.Bitmap,
|
|||
if dict == nil {
|
||||
continue
|
||||
}
|
||||
postings, err2 := dict.postingsList(term, drops[dictI])
|
||||
var err2 error
|
||||
postings, err2 = dict.postingsList(term, drops[dictI], postings)
|
||||
if err2 != nil {
|
||||
return nil, 0, err2
|
||||
}
|
||||
|
|
|
@ -310,8 +310,8 @@ func compareSegments(a, b *Segment) string {
|
|||
continue
|
||||
}
|
||||
|
||||
aplist, aerr := adict.(*Dictionary).postingsList([]byte(next.Term), nil)
|
||||
bplist, berr := bdict.(*Dictionary).postingsList([]byte(next.Term), nil)
|
||||
aplist, aerr := adict.(*Dictionary).postingsList([]byte(next.Term), nil, nil)
|
||||
bplist, berr := bdict.(*Dictionary).postingsList([]byte(next.Term), nil, nil)
|
||||
if aerr != berr {
|
||||
rv = append(rv, fmt.Sprintf("field %s, term: %s, postingsList() errors different: %v %v",
|
||||
fieldName, next.Term, aerr, berr))
|
||||
|
|
|
@ -343,8 +343,9 @@ func (s *SegmentBase) DocNumbers(ids []string) (*roaring.Bitmap, error) {
|
|||
return nil, err
|
||||
}
|
||||
|
||||
var postings *PostingsList
|
||||
for _, id := range ids {
|
||||
postings, err := idDict.postingsList([]byte(id), nil)
|
||||
postings, err = idDict.postingsList([]byte(id), nil, postings)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue