Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor(routingprocessor): use MoveTo instead of CopyTo #8991

Conversation

pmalek-sumo
Copy link
Contributor

Description: use MoveTo instead of CopyTo

Link to tracking Issue: N/A

Testing: existing UTs

Documentation:

$ go test -v -count 1 -run ^$ -bench Benchmark -benchmem -count 1 .
goos: darwin
goarch: amd64
pkg: github.com/open-telemetry/opentelemetry-collector-contrib/processor/routingprocessor
cpu: Intel(R) Core(TM) i9-9980HK CPU @ 2.40GHz
Benchmark_MetricsRouting_ResourceAttribute
Benchmark_MetricsRouting_ResourceAttribute-16            1463461               813.2 ns/op           688 B/op         16 allocs/op
PASS
ok      github.com/open-telemetry/opentelemetry-collector-contrib/processor/routingprocessor    2.432s
$ go test -v -count 1 -run ^$ -bench Benchmark -benchmem -count 1 .
goos: darwin
goarch: amd64
pkg: github.com/open-telemetry/opentelemetry-collector-contrib/processor/routingprocessor
cpu: Intel(R) Core(TM) i9-9980HK CPU @ 2.40GHz
Benchmark_MetricsRouting_ResourceAttribute
Benchmark_MetricsRouting_ResourceAttribute-16            1694242               702.0 ns/op           592 B/op         15 allocs/op
PASS
ok      github.com/open-telemetry/opentelemetry-collector-contrib/processor/routingprocessor    2.328s

@@ -95,10 +95,10 @@ func (r *router) routeMetricsForResource(_ context.Context, tm pdata.Metrics) []
}

if rEntry, ok := routingMap[attrValue]; ok {
resMetrics.CopyTo(rEntry.resMetrics.AppendEmpty())
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good, I have a similar change as part of #7771 but I think @dmitryax had some concerns. What do you think about using MoveTo here, @dmitryax?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, this is different. I believe we can switch to MoveTo here, because it's called only once per each ResourceMetrics object, and we don't need to preserve the original pdata.Metrics object. But it's not the case for #7771.

@jpkrohling jpkrohling added the Skip Changelog PRs that do not require a CHANGELOG.md entry label Apr 5, 2022
@jpkrohling jpkrohling merged commit 94386ed into open-telemetry:main Apr 5, 2022
@sumo-drosiek sumo-drosiek deleted the routingprocessor-use-moveto-instead-of-copyto branch March 1, 2024 14:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Skip Changelog PRs that do not require a CHANGELOG.md entry
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants