[SDK] Added reserve for spans array in BatchSpanProcessor.#2724
Merged
Conversation
Added reserve for spans array in BatchSpanProcessor.
Helps to allocate the amount of memory needed for number of records so that dynamic memory allocation doesn't happen in the consume method.
.push_back() reallocates memory each time the method is called.
Using .reserve() would avoid memory reallocation as already the memory is allocated.
References:
https://cplusplus.com/reference/vector/vector/push_back/
https://cplusplus.com/reference/vector/vector/reserve/
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## main #2724 +/- ##
==========================================
+ Coverage 87.12% 87.67% +0.56%
==========================================
Files 200 190 -10
Lines 6109 5855 -254
==========================================
- Hits 5322 5133 -189
+ Misses 787 722 -65
|
marcalff
reviewed
Jun 27, 2024
marcalff
reviewed
Jun 27, 2024
Member
marcalff
left a comment
There was a problem hiding this comment.
Looks good to me, thanks for the fix.
See the suggested change to fix the CI failure on code format.
Co-authored-by: Marc Alff <marc.alff@free.fr>
Contributor
Author
|
Thanks for suggesting. I think CI Checks should starting running now. |
Member
|
Similar change can be done for BatchLogProcessor. @msiddhu just in case you can handle as separate as same PR :) |
Added reserve for spans array in BatchLogProcessor. Same as previously done for BatchSpanProcessor
Contributor
Author
|
Thanks for pointing out. Made the suggested changes. Please review. |
ThomsonTan
reviewed
Jun 27, 2024
marcalff
reviewed
Jun 27, 2024
malkia
added a commit
to malkia/opentelemetry-cpp
that referenced
this pull request
Jun 28, 2024
[SDK] Added reserve for spans array in BatchSpanProcessor. (open-telemetry#2724)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Changes
Added
.reserveforspans_arrin BatchSpanProcessor (Small Optimization)Helps to allocate the amount of memory needed for number of records so that dynamic memory allocation doesn't happen in the consume method.
.push_back()reallocates memory each time the method is called.Using
.reserve()would avoid memory reallocation as already the memory is allocated.References:
C++ Vector push_back
C++ Vector reserve
CHANGELOG.mdupdated for non-trivial changes