Skip to content

Commit

Permalink
Preallocate memory to reduce GC load (#32905)
Browse files Browse the repository at this point in the history
Preallocating memory reduces the load Go needs to handle and track allocated memory regions. This also reduces GC load.

Signed-off-by: Florian Lehner <[email protected]>
  • Loading branch information
florianl authored Aug 30, 2022
1 parent 2400e9a commit 3668fd6
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 2 deletions.
2 changes: 1 addition & 1 deletion libbeat/template/load_integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down
2 changes: 1 addition & 1 deletion x-pack/filebeat/input/httpjson/transform_registry.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down

0 comments on commit 3668fd6

Please sign in to comment.