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

[query] Improve readerIterator performance #3512

Merged
merged 1 commit into from
May 22, 2021
Merged
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
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