Skip to content

Commit

Permalink
Reuse buffer for hash computation in the engine. (grafana#2218)
Browse files Browse the repository at this point in the history
Signed-off-by: Cyril Tovena <[email protected]>
  • Loading branch information
cyriltovena authored Jun 19, 2020
1 parent 314531c commit 7212564
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions pkg/logql/evaluator.go
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,8 @@ func vectorAggEvaluator(
if err != nil {
return nil, err
}
lb := labels.NewBuilder(nil)
buf := make([]byte, 0, 1024)

return newStepEvaluator(func() (bool, int64, promql.Vector) {
next, ts, vec := nextEvaluator.Next()
Expand All @@ -210,17 +212,17 @@ func vectorAggEvaluator(
groupingKey uint64
)
if expr.grouping.without {
groupingKey, _ = metric.HashWithoutLabels(make([]byte, 0, 1024), expr.grouping.groups...)
groupingKey, buf = metric.HashWithoutLabels(buf, expr.grouping.groups...)
} else {
groupingKey, _ = metric.HashForLabels(make([]byte, 0, 1024), expr.grouping.groups...)
groupingKey, buf = metric.HashForLabels(buf, expr.grouping.groups...)
}
group, ok := result[groupingKey]
// Add a new group if it doesn't exist.
if !ok {
var m labels.Labels

if expr.grouping.without {
lb := labels.NewBuilder(metric)
lb.Reset(metric)
lb.Del(expr.grouping.groups...)
lb.Del(labels.MetricName)
m = lb.Labels()
Expand Down

0 comments on commit 7212564

Please sign in to comment.