From 21d0682048a2654227abf7e869c82c8bc646b837 Mon Sep 17 00:00:00 2001 From: Cyril Tovena Date: Mon, 15 Jun 2020 09:49:12 -0400 Subject: [PATCH] Reuse buffer for hash computation in the engine. Signed-off-by: Cyril Tovena --- pkg/logql/evaluator.go | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/pkg/logql/evaluator.go b/pkg/logql/evaluator.go index 2244c539836b6..346107c5bdccb 100644 --- a/pkg/logql/evaluator.go +++ b/pkg/logql/evaluator.go @@ -188,6 +188,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() @@ -209,9 +211,9 @@ 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. @@ -219,7 +221,7 @@ func vectorAggEvaluator( 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()