diff --git a/pkg/ottl/expression.go b/pkg/ottl/expression.go index fcc0cd7c202a..c0d36a948905 100644 --- a/pkg/ottl/expression.go +++ b/pkg/ottl/expression.go @@ -208,6 +208,7 @@ func newMapGetter[K any](mapValues map[string]Getter[K]) (Getter[K], error) { func (m *mapGetter[K]) Get(ctx context.Context, tCtx K) (any, error) { result := pcommon.NewMap() + result.EnsureCapacity(len(m.mapValues)) for k, v := range m.mapValues { val, err := v.Get(ctx, tCtx) if err != nil { @@ -219,6 +220,7 @@ func (m *mapGetter[K]) Get(ctx context.Context, tCtx K) (any, error) { typedVal.CopyTo(target) case []any: target := result.PutEmpty(k).SetEmptySlice() + target.EnsureCapacity(len(typedVal)) for _, el := range typedVal { switch typedEl := el.(type) { case pcommon.Map: diff --git a/pkg/ottl/ottlfuncs/func_extract_grok_patterns.go b/pkg/ottl/ottlfuncs/func_extract_grok_patterns.go index aaa313eed228..b5b55a7ad19e 100644 --- a/pkg/ottl/ottlfuncs/func_extract_grok_patterns.go +++ b/pkg/ottl/ottlfuncs/func_extract_grok_patterns.go @@ -107,6 +107,7 @@ func extractGrokPatterns[K any](target, pattern ottl.StringGetter[K], nco ottl.O } result := pcommon.NewMap() + result.EnsureCapacity(len(matches)) for k, v := range matches { switch val := v.(type) { case bool: