Performance: Add preallocation for some slices (#59593)

This commit is contained in:
Denis Limarev
2023-01-11 23:03:37 +06:00
committed by GitHub
parent 8bda8b8272
commit 90badc8729
8 changed files with 11 additions and 11 deletions
+2 -3
View File
@@ -1,6 +1,7 @@
package conditions
import (
gocontext "context"
"errors"
"fmt"
"strings"
@@ -10,8 +11,6 @@ import (
"github.com/grafana/grafana/pkg/tsdb/legacydata/interval"
"github.com/grafana/grafana/pkg/tsdb/prometheus"
gocontext "context"
"github.com/grafana/grafana-plugin-sdk-go/data"
"github.com/grafana/grafana/pkg/components/null"
@@ -61,7 +60,7 @@ func (c *QueryCondition) Eval(context *alerting.EvalContext, requestHandler lega
// matches represents all the series that violate the alert condition
var matches []*alerting.EvalMatch
// allMatches capture all evaluation matches irregardless on whether the condition is met or not
var allMatches []*alerting.EvalMatch
allMatches := make([]*alerting.EvalMatch, 0, len(seriesList))
for _, series := range seriesList {
reducedValue := c.Reducer.Reduce(series)
@@ -144,6 +144,7 @@ func (gcn *GoogleChatNotifier) Notify(evalContext *alerting.EvalContext) error {
}
// add a text paragraph widget for the fields
//nolint:prealloc // break block
var fields []textParagraphWidget
fieldLimitCount := 4
for index, evt := range evalContext.EvalMatches {