Skip to content

Commit

Permalink
[query] Improve readerIterator performance (m3db#3512)
Browse files Browse the repository at this point in the history
  • Loading branch information
arnikola authored May 22, 2021
1 parent de6d212 commit 4477597
Showing 1 changed file with 10 additions and 12 deletions.
22 changes: 10 additions & 12 deletions src/dbnode/encoding/m3tsz/iterator.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ type readerIterator struct {
mult uint8 // current int multiplier
sig uint8 // current number of significant bits for int diff

curr ts.Datapoint
intOptimized bool // whether encoding scheme is optimized for ints
isFloat bool // whether encoding is in int or float

Expand Down Expand Up @@ -94,6 +95,14 @@ func (it *readerIterator) Next() bool {
it.readFirstValue()
}

it.curr.Timestamp = it.tsIterator.PrevTime.ToTime()
it.curr.TimestampNanos = it.tsIterator.PrevTime
if !it.intOptimized || it.isFloat {
it.curr.Value = math.Float64frombits(it.floatIter.PrevFloatBits)
} else {
it.curr.Value = convertFromIntFloat(it.intVal, it.mult)
}

return it.hasNext()
}

Expand Down Expand Up @@ -219,18 +228,7 @@ func (it *readerIterator) readBits(numBits uint8) (res uint64) {
// Users should not hold on to the returned Annotation object as it may get invalidated when
// the iterator calls Next().
func (it *readerIterator) Current() (ts.Datapoint, xtime.Unit, ts.Annotation) {
dp := ts.Datapoint{
Timestamp: it.tsIterator.PrevTime.ToTime(),
TimestampNanos: it.tsIterator.PrevTime,
}

if !it.intOptimized || it.isFloat {
dp.Value = math.Float64frombits(it.floatIter.PrevFloatBits)
} else {
dp.Value = convertFromIntFloat(it.intVal, it.mult)
}

return dp, it.tsIterator.TimeUnit, it.tsIterator.PrevAnt
return it.curr, it.tsIterator.TimeUnit, it.tsIterator.PrevAnt
}

// Err returns the error encountered
Expand Down

0 comments on commit 4477597

Please sign in to comment.