scorch zap loadChunk reuses Location slices
This commit is contained in:
parent
4dbb4b1495
commit
dd7d93ee5e
|
@ -171,7 +171,8 @@ type PostingsIterator struct {
|
|||
|
||||
locBitmap *roaring.Bitmap
|
||||
|
||||
next Posting
|
||||
next Posting // reused across Next() calls
|
||||
nextLocs []Location // reused across Next() calls
|
||||
}
|
||||
|
||||
func (i *PostingsIterator) loadChunk(chunk int) error {
|
||||
|
@ -333,7 +334,8 @@ func (i *PostingsIterator) Next() (segment.Posting, error) {
|
|||
}
|
||||
}
|
||||
|
||||
i.next = Posting{} // clear the struct.
|
||||
reuseLocs := i.next.locs // hold for reuse before struct clearing
|
||||
i.next = Posting{} // clear the struct
|
||||
rv := &i.next
|
||||
rv.iterator = i
|
||||
rv.docNum = uint64(n)
|
||||
|
@ -346,15 +348,23 @@ func (i *PostingsIterator) Next() (segment.Posting, error) {
|
|||
}
|
||||
rv.norm = math.Float32frombits(uint32(normBits))
|
||||
if i.locBitmap.Contains(n) {
|
||||
// read off 'freq' locations
|
||||
rv.locs = make([]segment.Location, rv.freq)
|
||||
locs := make([]Location, rv.freq)
|
||||
// read off 'freq' locations, into reused slices
|
||||
if cap(i.nextLocs) >= int(rv.freq) {
|
||||
i.nextLocs = i.nextLocs[0:rv.freq]
|
||||
} 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)
|
||||
}
|
||||
for j := 0; j < int(rv.freq); j++ {
|
||||
err := i.readLocation(&locs[j])
|
||||
err := i.readLocation(&i.nextLocs[j])
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
rv.locs[j] = &locs[j]
|
||||
rv.locs[j] = &i.nextLocs[j]
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue