0
0
Fork 0

scorch zap postingsIter reuses nextLocs/nextSegmentLocs

The previous code would inefficiently throw away the nextLocs and
would also throw away the []segment.Location slice if there were no
locations, such as if it was a 1-hit postings list.

This change tries to reuse the nextLocs/nextSegmentLocs for all cases.
This commit is contained in:
Steve Yen 2018-03-17 10:59:57 -07:00
parent 6540b197d4
commit db792717a6
1 changed files with 13 additions and 8 deletions

View File

@ -154,6 +154,9 @@ func (p *PostingsList) iterator(rv *PostingsIterator) *PostingsIterator {
freqChunkOffsets := rv.freqChunkOffsets[:0]
locChunkOffsets := rv.locChunkOffsets[:0]
nextLocs := rv.nextLocs[:0]
nextSegmentLocs := rv.nextSegmentLocs[:0]
buf := rv.buf
*rv = PostingsIterator{} // clear the struct
@ -167,6 +170,9 @@ func (p *PostingsList) iterator(rv *PostingsIterator) *PostingsIterator {
rv.freqChunkOffsets = freqChunkOffsets
rv.locChunkOffsets = locChunkOffsets
rv.nextLocs = nextLocs
rv.nextSegmentLocs = nextSegmentLocs
rv.buf = buf
}
rv.postings = p
@ -314,8 +320,9 @@ type PostingsIterator struct {
locChunkOffsets []uint64
locChunkStart uint64
next Posting // reused across Next() calls
nextLocs []Location // reused across Next() calls
next Posting // reused across Next() calls
nextLocs []Location // reused across Next() calls
nextSegmentLocs []segment.Location // reused across Next() calls
docNum1Hit uint64
normBits1Hit uint64
@ -469,8 +476,7 @@ func (i *PostingsIterator) Next() (segment.Posting, error) {
return nil, err
}
reuseLocs := i.next.locs // hold for reuse before struct clearing
i.next = Posting{} // clear the struct
i.next = Posting{} // clear the struct
rv := &i.next
rv.docNum = docNum
@ -491,11 +497,10 @@ func (i *PostingsIterator) Next() (segment.Posting, error) {
} else {
i.nextLocs = make([]Location, rv.freq)
}
if cap(reuseLocs) >= int(rv.freq) {
rv.locs = reuseLocs[0:rv.freq]
} else {
rv.locs = make([]segment.Location, rv.freq)
if cap(i.nextSegmentLocs) < int(rv.freq) {
i.nextSegmentLocs = make([]segment.Location, rv.freq)
}
rv.locs = i.nextSegmentLocs[0:rv.freq]
for j := 0; j < int(rv.freq); j++ {
err := i.readLocation(&i.nextLocs[j])
if err != nil {