From d830591cdc5e4be96658c0aab982fd29e9ba9192 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?G=C3=A1bor=20Farkas?= Date: Wed, 12 Apr 2023 14:45:21 +0200 Subject: [PATCH] Revert "Prometheus: Reduce allocations parsing exemplars" (#66367) Revert "Prometheus: Reduce allocations parsing exemplars (#58959)" This reverts commit a1f2d0e20582e3773ac623c5e0d55300fdbdc620. --- pkg/tsdb/prometheus/querydata/framing_bench_test.go | 1 - pkg/util/converter/prom.go | 7 +++---- 2 files changed, 3 insertions(+), 5 deletions(-) diff --git a/pkg/tsdb/prometheus/querydata/framing_bench_test.go b/pkg/tsdb/prometheus/querydata/framing_bench_test.go index f1f96e01616..fa63a4fa85d 100644 --- a/pkg/tsdb/prometheus/querydata/framing_bench_test.go +++ b/pkg/tsdb/prometheus/querydata/framing_bench_test.go @@ -41,7 +41,6 @@ func BenchmarkExemplarJson(b *testing.B) { tCtx, err := setup(true) require.NoError(b, err) b.ResetTimer() - b.ReportAllocs() for n := 0; n < b.N; n++ { res := http.Response{ StatusCode: 200, diff --git a/pkg/util/converter/prom.go b/pkg/util/converter/prom.go index a771a9336e4..a71968abf2e 100644 --- a/pkg/util/converter/prom.go +++ b/pkg/util/converter/prom.go @@ -228,8 +228,8 @@ func readArrayData(iter *jsoniter.Iterator) backend.DataResponse { } // For consistent ordering read values to an array not a map -func readLabelsAsPairs(iter *jsoniter.Iterator, pairs [][2]string) [][2]string { - pairs = pairs[:0] +func readLabelsAsPairs(iter *jsoniter.Iterator) [][2]string { + pairs := make([][2]string, 0, 10) for k := iter.ReadObject(); k != ""; k = iter.ReadObject() { pairs = append(pairs, [2]string{k, iter.ReadString()}) } @@ -270,7 +270,7 @@ func readLabelsOrExemplars(iter *jsoniter.Iterator) (*data.Frame, [][2]string) { case "labels": max := 0 - for _, pair := range readLabelsAsPairs(iter, pairs) { + for _, pair := range readLabelsAsPairs(iter) { k := pair[0] v := pair[1] f, ok := lookup[k] @@ -305,7 +305,6 @@ func readLabelsOrExemplars(iter *jsoniter.Iterator) (*data.Frame, [][2]string) { } default: v := fmt.Sprintf("%v", iter.Read()) - pairs = pairs[:0] pairs = append(pairs, [2]string{l1Field, v}) } }