Skip to content

Commit

Permalink
Added reserve for spans array in BatchSpanProcessor.
Browse files Browse the repository at this point in the history
    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/
  • Loading branch information
msiddhu authored Jun 27, 2024
1 parent 7701239 commit 2d120cc
Showing 1 changed file with 4 additions and 0 deletions.
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;
}

//reserves the space for the number of records to be exported
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 2d120cc

Please sign in to comment.