From 2d120ccb4f79bc22b3575d47db5931348726bf43 Mon Sep 17 00:00:00 2001 From: Siddhartha Malladi Date: Thu, 27 Jun 2024 10:59:02 -0400 Subject: [PATCH] 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/ --- sdk/src/trace/batch_span_processor.cc | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/sdk/src/trace/batch_span_processor.cc b/sdk/src/trace/batch_span_processor.cc index c5e72f8176..cd917e3505 100644 --- a/sdk/src/trace/batch_span_processor.cc +++ b/sdk/src/trace/batch_span_processor.cc @@ -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> range) noexcept { range.ForEach([&](AtomicUniquePtr &ptr) {