Skip to content

Commit 3feca98

Browse files
committed
DPL: avoid one allocation per match
The constructed Stack object is thrown away immediately after the matching, introducing unneeded memory churn.
1 parent ee0b597 commit 3feca98

1 file changed

Lines changed: 10 additions & 6 deletions

File tree

Framework/Core/src/DataDescriptorMatcher.cxx

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,9 @@
1717
#include "Framework/RuntimeError.h"
1818
#include "Headers/DataHeader.h"
1919
#include "Headers/Stack.h"
20+
#include <array>
2021
#include <iostream>
22+
#include <memory_resource>
2123

2224
namespace o2::framework::data_matcher
2325
{
@@ -202,9 +204,10 @@ bool DataDescriptorMatcher::match(ConcreteDataMatcher const& matcher, VariableCo
202204
dh.dataOrigin = matcher.origin;
203205
dh.dataDescription = matcher.description;
204206
dh.subSpecification = matcher.subSpec;
205-
DataProcessingHeader dph;
206-
dph.startTime = 0;
207-
header::Stack s{dh, dph};
207+
DataProcessingHeader dph{0, 0, 0};
208+
alignas(std::max_align_t) std::array<std::byte, sizeof(header::DataHeader) + sizeof(DataProcessingHeader) + alignof(std::max_align_t)> buffer;
209+
std::pmr::monotonic_buffer_resource resource{buffer.data(), buffer.size(), std::pmr::null_memory_resource()};
210+
header::Stack s{header::Stack::allocator_type{&resource}, dh, dph};
208211

209212
return this->match(reinterpret_cast<char const*>(s.data()), context);
210213
}
@@ -217,9 +220,10 @@ bool DataDescriptorMatcher::match(ConcreteDataTypeMatcher const& matcher, Variab
217220
dh.dataOrigin = matcher.origin;
218221
dh.dataDescription = matcher.description;
219222
dh.subSpecification = 0;
220-
DataProcessingHeader dph;
221-
dph.startTime = 0;
222-
header::Stack s{dh, dph};
223+
DataProcessingHeader dph{0, 0, 0};
224+
alignas(std::max_align_t) std::array<std::byte, sizeof(header::DataHeader) + sizeof(DataProcessingHeader) + alignof(std::max_align_t)> buffer;
225+
std::pmr::monotonic_buffer_resource resource{buffer.data(), buffer.size(), std::pmr::null_memory_resource()};
226+
header::Stack s{header::Stack::allocator_type{&resource}, dh, dph};
223227

224228
return this->match(reinterpret_cast<char const*>(s.data()), context);
225229
}

0 commit comments

Comments
 (0)