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

Reuse slice for the range vector allocations. #2219

Merged
merged 1 commit into from
Jun 19, 2020
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
10 changes: 7 additions & 3 deletions pkg/logql/range_vector.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,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 @@ -130,19 +131,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