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

Introduce Equal comparison in pcommon types #12594

Merged
merged 9 commits into from
Mar 12, 2025

Conversation

dmathieu
Copy link
Member

Description

This introduces .Equal() methods to most pcommon types, so equality comparison can be performed with no allocations.

The types Equal is added to are:

  • Value
  • ByteSlice
  • Float64Slice
  • Int32Slice
  • Int64Slice
  • StringSlice
  • Uint64Slice
  • Map
  • Slice

The original intent was to add it to Value. However, to be able to handle every type in there, I had to also add it to the other types, some of which are coming too because they are auto-generated.

Link to tracking issue

Fixes #12561

This is the same thing as #12568, but with comparison of pcommon types rather than raw ones.

Testing

Here are the results from the new benchmarks.

goos: darwin
goarch: arm64
pkg: go.opentelemetry.io/collector/pdata/pcommon
cpu: Apple M1 Max
BenchmarkByteSliceEqual-10              513754251                2.181 ns/op           0 B/op          0 allocs/op
BenchmarkFloat64SliceEqual-10           550760200                2.189 ns/op           0 B/op          0 allocs/op
BenchmarkInt32SliceEqual-10             550836993                2.186 ns/op           0 B/op          0 allocs/op
BenchmarkInt64SliceEqual-10             536615931                2.178 ns/op           0 B/op          0 allocs/op
BenchmarkStringSliceEqual-10            166586130                7.055 ns/op           0 B/op          0 allocs/op
BenchmarkUInt64SliceEqual-10            550221884                2.191 ns/op           0 B/op          0 allocs/op
BenchmarkMapEqual-10                    100000000               10.29 ns/op            0 B/op          0 allocs/op
BenchmarkSliceEqual-10                  165937951                7.185 ns/op           0 B/op          0 allocs/op
BenchmarkValueEqual/nil-10              425391500                2.817 ns/op           0 B/op          0 allocs/op
BenchmarkValueEqual/strings-10          226853427                5.441 ns/op           0 B/op          0 allocs/op
BenchmarkValueEqual/booleans-10         296628630                4.080 ns/op           0 B/op          0 allocs/op
BenchmarkValueEqual/ints-10             296841543                4.070 ns/op           0 B/op          0 allocs/op
BenchmarkValueEqual/doubles-10          296242837                4.050 ns/op           0 B/op          0 allocs/op
BenchmarkValueEqual/byte_slices-10              173515455                6.855 ns/op           0 B/op          0 allocs/op
BenchmarkValueEqual/slices-10                   83512392                14.10 ns/op            0 B/op          0 allocs/op
BenchmarkValueEqual/maps-10                     63556654                18.41 ns/op            0 B/op          0 allocs/op
PASS
ok      go.opentelemetry.io/collector/pdata/pcommon     24.650s

@dmathieu dmathieu marked this pull request as ready for review March 10, 2025 10:29
@dmathieu dmathieu requested a review from a team as a code owner March 10, 2025 10:29
@dmathieu dmathieu requested a review from jmacd March 10, 2025 10:29
Copy link

codecov bot commented Mar 10, 2025

Codecov Report

Attention: Patch coverage is 93.33333% with 4 lines in your changes missing coverage. Please review.

Project coverage is 92.09%. Comparing base (983cc46) to head (589d916).
Report is 1 commits behind head on main.

Files with missing lines Patch % Lines
pdata/pcommon/map.go 82.35% 2 Missing and 1 partial ⚠️
pdata/pcommon/value.go 95.45% 1 Missing ⚠️

❌ Your patch status has failed because the patch coverage (93.33%) is below the target coverage (95.00%). You can increase the patch coverage or adjust the target coverage.

Additional details and impacted files
@@           Coverage Diff           @@
##             main   #12594   +/-   ##
=======================================
  Coverage   92.09%   92.09%           
=======================================
  Files         473      473           
  Lines       25590    25650   +60     
=======================================
+ Hits        23567    23623   +56     
- Misses       1612     1615    +3     
- Partials      411      412    +1     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@github-actions github-actions bot requested a review from bogdandrutu March 11, 2025 09:41
@github-actions github-actions bot requested a review from bogdandrutu March 12, 2025 16:30
@bogdandrutu bogdandrutu added this pull request to the merge queue Mar 12, 2025
Merged via the queue into open-telemetry:main with commit 37e38f9 Mar 12, 2025
54 of 55 checks passed
@dmathieu dmathieu deleted the pcommon-equal branch March 12, 2025 20:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add Equal() helper method to pcommon.Value
2 participants