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 #12568

Open
wants to merge 7 commits into
base: main
Choose a base branch
from

Conversation

dmathieu
Copy link
Member

@dmathieu dmathieu commented Mar 5, 2025

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

Testing

Here are the results from the new benchmarks.

go test -bench=. ./...
goos: darwin
goarch: arm64
pkg: go.opentelemetry.io/collector/pdata/pcommon
cpu: Apple M1 Max
BenchmarkByteSliceEqual-10              518354892                2.216 ns/op           0 B/op          0 allocs/op
BenchmarkFloat64SliceEqual-10           536303960                2.213 ns/op           0 B/op          0 allocs/op
BenchmarkInt32SliceEqual-10             544727418                2.208 ns/op           0 B/op          0 allocs/op
BenchmarkInt64SliceEqual-10             544786770                2.218 ns/op           0 B/op          0 allocs/op
BenchmarkStringSliceEqual-10            161984316                7.491 ns/op           0 B/op          0 allocs/op
BenchmarkUInt64SliceEqual-10            543405762                2.211 ns/op           0 B/op          0 allocs/op
BenchmarkMapEqual-10                    95199063                12.37 ns/op            0 B/op          0 allocs/op
BenchmarkSliceEqual-10                  180702288                6.640 ns/op           0 B/op          0 allocs/op
BenchmarkValueEqual/nil-10              583397124                2.065 ns/op           0 B/op          0 allocs/op
BenchmarkValueEqual/strings-10          252571316                4.735 ns/op           0 B/op          0 allocs/op
BenchmarkValueEqual/booleans-10         421377843                2.865 ns/op           0 B/op          0 allocs/op
BenchmarkValueEqual/ints-10             420362413                2.861 ns/op           0 B/op          0 allocs/op
BenchmarkValueEqual/ints8-10            420972375                2.867 ns/op           0 B/op          0 allocs/op
BenchmarkValueEqual/ints16-10           420432676                2.865 ns/op           0 B/op          0 allocs/op
BenchmarkValueEqual/ints32-10           418548438                2.871 ns/op           0 B/op          0 allocs/op
BenchmarkValueEqual/ints64-10           419564282                2.868 ns/op           0 B/op          0 allocs/op
BenchmarkValueEqual/uints-10            420894673                2.874 ns/op           0 B/op          0 allocs/op
BenchmarkValueEqual/uints8-10           419992580                2.864 ns/op           0 B/op          0 allocs/op
BenchmarkValueEqual/uints16-10          419492168                2.869 ns/op           0 B/op          0 allocs/op
BenchmarkValueEqual/uints32-10          418700623                2.862 ns/op           0 B/op          0 allocs/op
BenchmarkValueEqual/uints64-10          419113983                2.870 ns/op           0 B/op          0 allocs/op
BenchmarkValueEqual/floats32-10         419409087                2.866 ns/op           0 B/op          0 allocs/op
BenchmarkValueEqual/floats64-10         418236566                2.872 ns/op           0 B/op          0 allocs/op
BenchmarkValueEqual/byte_slices-10              223578720                5.368 ns/op           0 B/op          0 allocs/op
BenchmarkValueEqual/slices-10                   140243206                8.587 ns/op           0 B/op          0 allocs/op
BenchmarkValueEqual/maps-10                     72963666                16.25 ns/op            0 B/op          0 allocs/op
PASS
ok      go.opentelemetry.io/collector/pdata/pcommon     40.049s

@github-actions github-actions bot requested review from bogdandrutu and dmitryax March 5, 2025 14:40
@dmathieu dmathieu marked this pull request as ready for review March 5, 2025 14:50
@dmathieu dmathieu requested a review from a team as a code owner March 5, 2025 14:50
@dmathieu
Copy link
Member Author

dmathieu commented Mar 5, 2025

cc @jmacd, as you asked for the change in the linked issue.

Copy link

codecov bot commented Mar 5, 2025

Codecov Report

Attention: Patch coverage is 98.93617% with 1 line in your changes missing coverage. Please review.

Project coverage is 92.20%. Comparing base (72a8471) to head (dc8bc57).

Files with missing lines Patch % Lines
pdata/pcommon/value.go 98.36% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main   #12568      +/-   ##
==========================================
+ Coverage   92.18%   92.20%   +0.02%     
==========================================
  Files         469      469              
  Lines       25395    25489      +94     
==========================================
+ Hits        23410    23503      +93     
- Misses       1574     1575       +1     
  Partials      411      411              

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

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
1 participant