Skip to content

Commit

Permalink
[SDK] Added reserve for spans array in BatchSpanProcessor. (open-tel…
Browse files Browse the repository at this point in the history
…emetry#2724)

* Added reserve for spans array in BatchSpanProcessor.

    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/

* Added reserve for spans array in BatchLogProcessor.

Added reserve for spans array in BatchLogProcessor. Same as previously done for BatchSpanProcessor

* Update batch_log_record_processor.cc

* Update batch_span_processor.cc

* Update sdk/src/logs/batch_log_record_processor.cc
  • Loading branch information
msiddhu authored Jun 27, 2024
1 parent 7701239 commit f0e0ef0
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 0 deletions.
2 changes: 2 additions & 0 deletions sdk/src/logs/batch_log_record_processor.cc
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,8 @@ void BatchLogRecordProcessor::Export()
break;
}

// Reserve space for the number of records
records_arr.reserve(num_records_to_export);
buffer_.Consume(num_records_to_export,
[&](CircularBufferRange<AtomicUniquePtr<Recordable>> range) noexcept {
range.ForEach([&](AtomicUniquePtr<Recordable> &ptr) {
Expand Down
4 changes: 4 additions & 0 deletions sdk/src/trace/batch_span_processor.cc
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,10 @@ void BatchSpanProcessor::Export()
NotifyCompletion(notify_force_flush, exporter_, synchronization_data_);
break;
}

// Reserve space for the number of records
spans_arr.reserve(num_records_to_export);

buffer_.Consume(num_records_to_export,
[&](CircularBufferRange<AtomicUniquePtr<Recordable>> range) noexcept {
range.ForEach([&](AtomicUniquePtr<Recordable> &ptr) {
Expand Down

0 comments on commit f0e0ef0

Please sign in to comment.