Skip to content

Commit

Permalink
Reuse slice for the range vector allocations. (#2219)
Browse files Browse the repository at this point in the history
Signed-off-by: Cyril Tovena <cyril.tovena@gmail.com>
  • Loading branch information
cyriltovena authored Jun 19, 2020
1 parent 7212564 commit 91158ab
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions pkg/logql/range_vector.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ type rangeVectorIterator struct {
selRange, step, end, current int64
window map[string]*promql.Series
metrics map[string]labels.Labels
at []promql.Sample
}

func newRangeVectorIterator(
Expand Down Expand Up @@ -135,19 +136,22 @@ func (r *rangeVectorIterator) load(start, end int64) {
}

func (r *rangeVectorIterator) At(aggregator RangeVectorAggregator) (int64, promql.Vector) {
result := make([]promql.Sample, 0, len(r.window))
if r.at == nil {
r.at = make([]promql.Sample, 0, len(r.window))
}
r.at = r.at[:0]
// convert ts from nano to milli seconds as the iterator work with nanoseconds
ts := r.current / 1e+6
for _, series := range r.window {
result = append(result, promql.Sample{
r.at = append(r.at, promql.Sample{
Point: promql.Point{
V: aggregator(series.Points),
T: ts,
},
Metric: series.Metric,
})
}
return ts, result
return ts, r.at
}

var seriesPool sync.Pool
Expand Down

0 comments on commit 91158ab

Please sign in to comment.