Skip to content

Commit e11df29

Browse files
committed
DPL Analysis: use unsafe cursor when reserving
There is no point in using the slow boundary checking / buffer resizing cursor when we reserve, since it's reasonable to expect that the memory will be there.
1 parent 4a5adf1 commit e11df29

2 files changed

Lines changed: 24 additions & 0 deletions

File tree

Framework/Core/include/Framework/AnalysisHelpers.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -513,9 +513,12 @@ struct WritingCursor {
513513

514514
/// reserve @a size rows when filling, so that we do not
515515
/// spend time reallocating the buffers.
516+
/// Switches the internal cursor to UnsafeAppend (no capacity check),
517+
/// which is safe because we just reserved enough space.
516518
void reserve(int64_t size)
517519
{
518520
mBuilder->reserve(typename persistent_table_t::column_types{}, size);
521+
cursor = std::move(FFL(mBuilder->template unsafeCursor<persistent_table_t>()));
519522
}
520523

521524
void release()

Framework/Core/include/Framework/TableBuilder.h

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -715,6 +715,18 @@ class TableBuilder
715715
};
716716
}
717717

718+
/// Same as persist, but uses UnsafeAppend (no capacity check).
719+
/// Only safe after reserve() has been called with the correct size.
720+
template <typename ARG0, typename... ARGS>
721+
requires(sizeof...(ARGS) > 0) || ShouldNotDeconstruct<ARG0>
722+
auto unsafePersist()
723+
{
724+
using FillTuple = std::tuple<typename BuilderMaker<ARG0>::FillType, typename BuilderMaker<ARGS>::FillType...>;
725+
return [holders = mHolders](unsigned int /*slot*/, typename BuilderMaker<ARG0>::FillType arg, typename BuilderMaker<ARGS>::FillType... args) -> void {
726+
TableBuilderHelpers::unsafeAppend(*(HoldersTupleIndexed<ARG0, ARGS...>*)holders, std::forward_as_tuple(arg, args...));
727+
};
728+
}
729+
718730
// Same as above, but starting from a o2::soa::Table, which has all the
719731
// information already available.
720732
template <typename T>
@@ -725,6 +737,15 @@ class TableBuilder
725737
}(typename T::table_t::persistent_columns_t{});
726738
}
727739

740+
/// Same as cursor(), but uses UnsafeAppend. Only safe after reserve().
741+
template <typename T>
742+
auto unsafeCursor()
743+
{
744+
return [this]<typename... Cs>(pack<Cs...>) {
745+
return this->template unsafePersist<typename Cs::type...>();
746+
}(typename T::table_t::persistent_columns_t{});
747+
}
748+
728749
template <typename... Cs>
729750
auto cursor(framework::pack<Cs...>)
730751
{

0 commit comments

Comments
 (0)