From 3fbe2bf1c8dd9350a7c11be20d3e91c959c5ca73 Mon Sep 17 00:00:00 2001 From: Aliaksandr Valialkin Date: Tue, 2 Mar 2021 18:41:06 +0200 Subject: [PATCH] lib/promscrape: pre-allocate space for a map in mergeLabels This should reduce the number of memory allocations when discovering big number of targets --- lib/promscrape/config.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/promscrape/config.go b/lib/promscrape/config.go index 38b031677d..5ca2e5eae0 100644 --- a/lib/promscrape/config.go +++ b/lib/promscrape/config.go @@ -893,7 +893,7 @@ func getParamsFromLabels(labels []prompbmarshal.Label, paramsOrig map[string][]s func mergeLabels(job, scheme, target, metricsPath string, extraLabels, externalLabels, metaLabels map[string]string, params map[string][]string) []prompbmarshal.Label { // See https://prometheus.io/docs/prometheus/latest/configuration/configuration/#relabel_config - m := make(map[string]string) + m := make(map[string]string, 4 + len(externalLabels) + len(params) + len(extraLabels) + len(metaLabels)) for k, v := range externalLabels { m[k] = v }