Skip to content

[receiver/prometheusremotewritereceiver] Map.PutStr causes excessive memory allocations due to repeated slice expansions #44612

@leiwingqueen

Description

@leiwingqueen

Component(s)

receiver/prometheusremotewrite

Describe the issue you're reporting

Description

Summary

When adding multiple key-value pairs to a pcommon.Map using PutStr(), the underlying slice undergoes frequent reallocations and copies, leading to significant memory overhead. In production workloads with high cardinality metrics/logs, this becomes a major performance bottleneck.

Evidence

Memory profiling (pprof) shows that Map.EnsureCapacity accounts for 27.17% (0.94GB) of total memory allocation, even though it's never explicitly called in application code:

flat    flat%   sum%    cum     cum%
0.94GB  27.17%  60.05%  0.94GB  27.17%  go.opentelemetry.io/collector/pdata/pcommon.Map.EnsureCapacity
0.54GB  15.49%  75.55%  0.54GB  15.49%  go.opentelemetry.io/collector/pdata/pcommon.value.SetStr
0.41GB  11.82%  87.36%  0.42GB  12.17%  go.opentelemetry.io/collector/pdata/pcommon.Map.PutInt

Root Cause

The current PutStr implementation relies on Go's built-in append:

Tip

React with 👍 to help prioritize this issue. Please use comments to provide useful context, avoiding +1 or me too, to help us triage it. Learn more here.

Metadata

Metadata

Assignees

Type

No type
No fields configured for issues without a type.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions