lib/promscrape: pre-allocate space for a map in mergeLabels

This should reduce the number of memory allocations when discovering big number of targets
This commit is contained in:
Aliaksandr Valialkin 2021-03-02 18:41:06 +02:00
parent ac5c47a9f5
commit 3fbe2bf1c8

View File

@ -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 { 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 // 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 { for k, v := range externalLabels {
m[k] = v m[k] = v
} }