From 3668fd6909afa261edc563d710a12fa879d5d588 Mon Sep 17 00:00:00 2001 From: Florian Lehner Date: Tue, 30 Aug 2022 08:44:53 +0200 Subject: [PATCH] Preallocate memory to reduce GC load (#32905) Preallocating memory reduces the load Go needs to handle and track allocated memory regions. This also reduces GC load. Signed-off-by: Florian Lehner --- libbeat/template/load_integration_test.go | 2 +- x-pack/filebeat/input/httpjson/transform_registry.go | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/libbeat/template/load_integration_test.go b/libbeat/template/load_integration_test.go index 63db5965f3b..e1d6c12311a 100644 --- a/libbeat/template/load_integration_test.go +++ b/libbeat/template/load_integration_test.go @@ -370,7 +370,7 @@ func TestESLoader_Load(t *testing.T) { require.NoError(t, err) p, ok := val.(map[string]interface{}) require.True(t, ok) - var properties []string + properties := make([]string, 0, len(p)) for k := range p { properties = append(properties, k) } diff --git a/x-pack/filebeat/input/httpjson/transform_registry.go b/x-pack/filebeat/input/httpjson/transform_registry.go index 53caa9ded4f..26a739494db 100644 --- a/x-pack/filebeat/input/httpjson/transform_registry.go +++ b/x-pack/filebeat/input/httpjson/transform_registry.go @@ -52,7 +52,7 @@ func (reg registry) String() string { var str string for namespace, m := range reg.namespaces { - var names []string + names := make([]string, 0, len(m)) for k := range m { names = append(names, k) }