From dcf1c0d59b85537c6e4923f0df8d933e5415d055 Mon Sep 17 00:00:00 2001 From: Solomon Jacobs Date: Fri, 21 Aug 2026 09:25:56 +0200 Subject: [PATCH] model: sort label names without boxing them into sort.Interface SignatureForLabels becomes allocation-free, which matters because it is the only exported way to hash a subset of a label set. Alertmanager hit this in its inhibitor: it calls the equivalent once per inhibition rule per alert on GET `/api/v2/alerts`. Signed-off-by: Solomon Jacobs --- model/signature.go | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/model/signature.go b/model/signature.go index dc8a0026c..b723e3bb2 100644 --- a/model/signature.go +++ b/model/signature.go @@ -14,7 +14,7 @@ package model import ( - "sort" + "slices" ) // SeparatorByte is a byte that cannot occur in valid UTF-8 sequences and is @@ -37,7 +37,7 @@ func LabelsToSignature(labels map[string]string) uint64 { for labelName := range labels { labelNames = append(labelNames, labelName) } - sort.Strings(labelNames) + slices.Sort(labelNames) sum := hashNew() for _, labelName := range labelNames { @@ -60,7 +60,7 @@ func labelSetToFingerprint(ls LabelSet) Fingerprint { for labelName := range ls { labelNames = append(labelNames, labelName) } - sort.Sort(labelNames) + slices.Sort(labelNames) sum := hashNew() for _, labelName := range labelNames { @@ -100,7 +100,7 @@ func SignatureForLabels(m Metric, labels ...LabelName) uint64 { return emptyLabelSignature } - sort.Sort(LabelNames(labels)) + slices.Sort(labels) sum := hashNew() for _, label := range labels { @@ -129,7 +129,7 @@ func SignatureWithoutLabels(m Metric, labels map[LabelName]struct{}) uint64 { if len(labelNames) == 0 { return emptyLabelSignature } - sort.Sort(labelNames) + slices.Sort(labelNames) sum := hashNew() for _, labelName := range labelNames {