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

[pdata] Migrate immutable primitive slices to mutable wrappers #5971

Merged
merged 1 commit into from
Sep 9, 2022

Conversation

dmitryax
Copy link
Member

@dmitryax dmitryax commented Aug 25, 2022

This PR changes API for primitive slice wrappers to allow changing items directly since it appeared to be expensive to update that data as immutable wrappers: it required making two copies to update a slice.

This is a solution alternative to #5947

Update #5859

The wrappers for primitive slices doesn't represent atomic objects, they are treated the same way as other "complex" collection wrapper e.g. pcommon.Slice or pcommon.Map

@dmitryax dmitryax requested review from a team and jpkrohling August 25, 2022 23:01
@bogdandrutu
Copy link
Member

We need a rebase on this.

@codecov
Copy link

codecov bot commented Aug 30, 2022

Codecov Report

Base: 91.98% // Head: 91.99% // Increases project coverage by +0.01% 🎉

Coverage data is based on head (ec1a2de) compared to base (48342e8).
Patch coverage: 89.92% of modified lines in pull request are covered.

❗ Current head ec1a2de differs from pull request most recent head 99b9d97. Consider uploading reports for the commit 99b9d97 to get more accurate results

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #5971      +/-   ##
==========================================
+ Coverage   91.98%   91.99%   +0.01%     
==========================================
  Files         213      213              
  Lines       13320    13358      +38     
==========================================
+ Hits        12252    12289      +37     
  Misses        850      850              
- Partials      218      219       +1     
Impacted Files Coverage Δ
pdata/pmetric/generated_metrics.go 95.57% <50.00%> (-0.60%) ⬇️
pdata/pcommon/common.go 97.64% <90.00%> (-0.48%) ⬇️
pdata/pcommon/generated_primitive_slice.go 94.87% <94.87%> (ø)
...data/internal/generated_wrapper_primitive_slice.go 100.00% <100.00%> (ø)
processor/batchprocessor/splitmetrics.go 98.61% <0.00%> (-0.02%) ⬇️
pdata/internal/json/attribute.go 100.00% <0.00%> (ø)
cmd/builder/internal/builder/config.go 83.82% <0.00%> (ø)
pdata/plog/json.go 98.18% <0.00%> (+0.05%) ⬆️
pdata/pmetric/metrics.go 78.81% <0.00%> (+10.16%) ⬆️

Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.

☔ View full report at Codecov.
📢 Do you have feedback about the report comment? Let us know in this issue.

@dmitryax dmitryax force-pushed the mutable-slices-2 branch 7 times, most recently from 3b978e2 to 92458f8 Compare September 1, 2022 20:26
@dmitryax dmitryax force-pushed the mutable-slices-2 branch 6 times, most recently from 4aedd34 to 30c0388 Compare September 7, 2022 18:21
Copy link
Member

@bogdandrutu bogdandrutu left a comment

Choose a reason for hiding this comment

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

I like it.

pdata/pcommon/generated_primitive_slice.go Outdated Show resolved Hide resolved
Change API for primitive slice wrappers to allow changing items as it appeared to be expensive to update that data as immutable wrappers: it requires making two copies to update a slice
}

// FromRaw copies raw []${itemType} into the slice ${structName}.
func (ms ${structName}) FromRaw(val []${itemType}) {
Copy link
Member Author

Choose a reason for hiding this comment

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

@bogdandrutu do you think we should return ms here?

Otherwise current inline usages of pcommon.NewImmutable...Slice() becomes pretty clunky

Copy link
Member Author

Choose a reason for hiding this comment

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

As for me, I'm not sure about that. I don't like returning it and I don't like how it complicates the usages

Copy link
Member Author

Choose a reason for hiding this comment

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

Let me apply current state of this PR on contrib, and we'll see

Copy link
Member Author

Choose a reason for hiding this comment

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

It looks pretty good open-telemetry/opentelemetry-collector-contrib#14016 I believe we should keep current version

Copy link
Member

@bogdandrutu bogdandrutu left a comment

Choose a reason for hiding this comment

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

Things to do in a followup PR:

  • Copying can be done in-place to save allocations.
  • No way of increasing the capacity or length. We can discuss about that API.
  • Add CopyTo/MoveTo and remove the copy logic from the parent's CopyTo.

@dmitryax
Copy link
Member Author

dmitryax commented Sep 9, 2022

Things to do in a followup PR:

Sounds good. I'll follow up on those

@bogdandrutu bogdandrutu merged commit 0075f95 into open-telemetry:main Sep 9, 2022
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.

2 participants