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

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

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 88.33333% with 7 lines in your changes missing coverage. Please review.

Project coverage is 92.17%. Comparing base (7d3e03e) to head (20f1b34).

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

❌ Your patch check has failed because the patch coverage (88.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.18%   92.17%   -0.01%     
==========================================
  Files         469      469              
  Lines       25394    25454      +60     
==========================================
+ Hits        23409    23462      +53     
- Misses       1574     1579       +5     
- Partials      411      413       +2     

☔ 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.


switch v.Type() {
case ValueTypeEmpty:
return v.Type() == c.Type()
Copy link
Member

Choose a reason for hiding this comment

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

Already checked, just return true.

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