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

[SDK] Added reserve for spans array in BatchSpanProcessor. #2724

Merged
merged 6 commits into from
Jun 27, 2024

Conversation

msiddhu
Copy link
Contributor

@msiddhu msiddhu commented Jun 27, 2024

Changes

Added .reserve for spans_arr in 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.md updated for non-trivial changes
  • Unit tests have been added
  • Changes in public API reviewed

    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/
@msiddhu msiddhu requested a review from a team June 27, 2024 15:02
Copy link

linux-foundation-easycla bot commented Jun 27, 2024

CLA Signed

The committers listed above are authorized under a signed CLA.

@marcalff marcalff changed the title Added reserve for spans array in BatchSpanProcessor. [SDK] Added reserve for spans array in BatchSpanProcessor. Jun 27, 2024
Copy link

codecov bot commented Jun 27, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 87.67%. Comparing base (497eaf4) to head (17aeaba).
Report is 91 commits behind head on main.

Additional details and impacted files

Impacted file tree graph

@@            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     
Files Coverage Δ
sdk/src/logs/batch_log_record_processor.cc 89.29% <100.00%> (+1.79%) ⬆️
sdk/src/trace/batch_span_processor.cc 94.12% <100.00%> (+1.70%) ⬆️

... and 105 files with indirect coverage changes

Copy link
Member

@marcalff marcalff left a comment

Choose a reason for hiding this comment

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

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>
@msiddhu
Copy link
Contributor Author

msiddhu commented Jun 27, 2024

Thanks for suggesting. I think CI Checks should starting running now.

Copy link
Member

@lalitb lalitb left a comment

Choose a reason for hiding this comment

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

Thanks,

@lalitb
Copy link
Member

lalitb commented Jun 27, 2024

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
@msiddhu
Copy link
Contributor Author

msiddhu commented Jun 27, 2024

Thanks for pointing out. Made the suggested changes. Please review.

Copy link
Member

@marcalff marcalff left a comment

Choose a reason for hiding this comment

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

LGTM, thanks for the fix.

@marcalff marcalff merged commit f0e0ef0 into open-telemetry:main Jun 27, 2024
51 checks passed
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)
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.

4 participants