Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
b3582e9
DPL Analysis: use sentinel for end iterator in grouped combinations
aalkin Dec 3, 2026
4241a07
DPL Analysis: use sentinel for end iterator in combinations
aalkin Dec 3, 2026
19cd187
DPL Analysis: reuse column map when constructing tables and their slices
aalkin Dec 3, 2026
e1d17df
DPL Analysis: reuse column iterators when constructing table slices
aalkin Dec 3, 2026
485120c
DPL Analysis: avoid copies in GroupSlicer process arguments return
aalkin Dec 3, 2026
625d195
DPL Analysis: cache slice info in GroupedCombinationsGenerator
aalkin Dec 3, 2026
8b83443
DPL Analysis: avoid temporary tuple and its copy in GroupedCombinatio…
aalkin Dec 3, 2026
492e763
DPL Analysis: explicit return types for slices to prevent copies
aalkin Dec 3, 2026
bb636d4
DPL Analysis: move bindings to the unfiltered iterator, so that a fil…
aalkin Dec 3, 2026
60f5311
DPL Analysis: speed up iterator copy; add benchmarks
aalkin Dec 3, 2026
2dae82c
DPL Analysis: keep cache location for slices in general case
aalkin Dec 3, 2026
0eb5a34
DPL Analysis: GroupSlicer returns full table by reference
aalkin Dec 4, 2026
6300969
DPL Analysis: give empty filtered slices an empty range to skip const…
aalkin Dec 4, 2026
d44cbfa
DPL Analysis: remove unnecessary heap allocation from Filtered
aalkin Dec 4, 2026
f9cb03e
DPL Analysis: workaround for copy elision issue
aalkin Dec 4, 2026
bae2f7b
DPL Analysis: skip selection slicing for empty ranges
aalkin Dec 4, 2026
df79b41
DPL Analysis: skip default-constructing an iterator when possible
aalkin Dec 4, 2026
d034823
Add a TODO with C++23 requirement
aalkin Dec 4, 2026
13f47e5
DPL Analysis: reduce shared_ptr copies when passing ArrowTableRef around
aalkin Dec 4, 2026
d3d36ec
DPL Analysis: avoid extra copies of SelectionVector
aalkin Dec 4, 2026
e9b052f
DPL Analysis: adopt gandiva::Selection as const&
aalkin Dec 4, 2026
2a00e3f
DPL Analysis: fix the tests: selection should not go out of the scope
aalkin Dec 4, 2026
d285b17
DPL Analysis: avoid copying selection in SmallGroups slices; avoid re…
aalkin Dec 4, 2026
d2e3314
DPL Analysis: add a benchmarks for extreme slicing cases
aalkin Dec 4, 2026
f5874b4
DPL Analysis: add SmallGroups slicing benchmark
aalkin Dec 4, 2026
9aec857
DPL Analysis: SmallGroups shortcut for a full selection; add benchmarks
aalkin Dec 4, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Framework/Core/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -367,6 +367,7 @@ foreach(b
ASoA
ASoAHelpers
EventMixing
SparseSlicing
HistogramRegistry
ExternalFairMQDeviceProxies
)
Expand Down
510 changes: 416 additions & 94 deletions Framework/Core/include/Framework/ASoA.h

Large diffs are not rendered by default.

23 changes: 14 additions & 9 deletions Framework/Core/include/Framework/ASoAHelpers.h
Original file line number Diff line number Diff line change
Expand Up @@ -1156,6 +1156,10 @@ struct CombinationsGenerator {
using CombinationType = typename P::CombinationType;

public:
/// End-of-iteration marker: the iterator itself knows when it is exhausted
struct CombinationsSentinel {
};

struct CombinationsIterator : public P {
public:
using reference = CombinationType&;
Expand Down Expand Up @@ -1195,38 +1199,39 @@ struct CombinationsGenerator {
{
return (lh.mIsEnd && rh.mIsEnd) || (lh.mCurrent == rh.mCurrent);
}
bool operator==(CombinationsSentinel) const
{
return this->mIsEnd;
}
};

using iterator = CombinationsIterator;
using const_iterator = CombinationsIterator;
using sentinel = CombinationsSentinel;

inline iterator begin()
{
return iterator(mBegin);
}
inline iterator end()
inline sentinel end()
{
return iterator(mEnd);
return {};
}
inline const_iterator begin() const
{
return iterator(mBegin);
}
inline const_iterator end() const
inline sentinel end() const
{
return iterator(mEnd);
return {};
}

CombinationsGenerator() = delete;
CombinationsGenerator(const P& policy) : mBegin(policy), mEnd(policy)
{
mEnd.moveToEnd();
}
CombinationsGenerator(const P& policy) : mBegin(policy) {}
~CombinationsGenerator() = default;

private:
iterator mBegin;
iterator mEnd;
};

template <typename T2, typename... T2s>
Expand Down
9 changes: 6 additions & 3 deletions Framework/Core/include/Framework/AnalysisHelpers.h
Original file line number Diff line number Diff line change
Expand Up @@ -964,7 +964,7 @@ auto getTableFromFilter(soa::is_filtered_table auto const& table, soa::Selection

auto getTableFromFilter(soa::is_not_filtered_table auto const& table, soa::SelectionVector&& selection)
{
return std::make_unique<o2::soa::Filtered<std::decay_t<decltype(table)>>>(std::vector{table.asArrowTableRef()}, std::forward<soa::SelectionVector>(selection));
return std::make_unique<o2::soa::Filtered<std::decay_t<decltype(table)>>>(o2::soa::makeTableOn<o2::soa::Filtered<std::decay_t<decltype(table)>>>(table.asArrowTableRef(), table, std::forward<soa::SelectionVector>(selection)));
}

void initializePartitionCaches(std::span<const uint32_t> hashes, std::shared_ptr<arrow::Schema> const& schema, expressions::Filter const& filter, gandiva::NodePtr& tree, gandiva::FilterPtr& gfilter);
Expand Down Expand Up @@ -1104,12 +1104,15 @@ auto Extend(T const& table)
}

/// Template function to attach dynamic columns on-the-fly (e.g. inside
/// process() function). Dynamic columns need to be compatible with the table.
/// process() function). Dynamic columns need to be compatible with the table
/// and must not be in it already. The result reuses the columns the table has
/// resolved, as the attached columns follow them and have no backing arrays.
template <soa::is_table T, soa::is_dynamic_column... Cs>
requires((!framework::has_type_v<Cs, typename T::columns_t> && ...))
auto Attach(T const& table)
{
using output_t = Join<T, o2::soa::Table<o2::aod::Hash<"JOIN"_h>, o2::aod::Hash<"JOIN/0"_h>, o2::aod::Hash<"JOIN"_h>, Cs...>>;
return output_t{{table.asArrowTableRef()}};
return output_t{table.asArrowTableRef(), table};
}
} // namespace o2::soa

Expand Down
45 changes: 24 additions & 21 deletions Framework/Core/include/Framework/AnalysisTask.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
#include "Framework/GroupSlicer.h"
#include "Framework/StructToTuple.h"
#include "Framework/TypeIdHelpers.h"
#include "Framework/VariantHelpers.h"
#include "Framework/ArrowTableSlicingCache.h"
#include "Framework/AnalysisDataModel.h"
#include "Framework/DanglingEdgesContext.h"
Expand Down Expand Up @@ -398,29 +399,31 @@ struct AnalysisDataProcessorBuilder {
if constexpr (soa::is_iterator<G>) {
auto slicer = GroupSlicer(groupingTable, associatedTables, slices, newOrigin);
for (auto& slice : slicer) {
auto associatedSlices = slice.associatedTables();
std::apply([&pointerReconstructor](auto&... table) {
(table.setPointerReconstructor(pointerReconstructor), ...);
},
associatedSlices);

overwriteInternalIndices(associatedSlices, associatedTables);
std::apply(
[&binder](auto&... x) mutable {
(binder(x), ...);
// the slices are passed as prvalues and bound to the parameters
// directly, so that they are not copied on their way to the process function
[&](auto&&... associatedSlices) {
auto prepareSlice = framework::overloaded{
[&]<typename S>(S&& t)
requires(!std::is_lvalue_reference_v<S>)
{
t.setPointerReconstructor(pointerReconstructor);
t.bindInternalIndicesTo(&std::get<std::decay_t<S>>(associatedTables));
binder(t);
},
// tables not related to the grouping table are passed as references to
// the full tables, which got the same bindings before the slicer was made
[](auto&) {}};
(prepareSlice(std::forward<decltype(associatedSlices)>(associatedSlices)), ...);

// bind partitions and grouping table
homogeneous_apply_refs_sized<numElements>([&groupingTable](auto& x) {
analysis_task_parsers::bindExternalIndicesPartition(x, &groupingTable);
return true;
},
associatedSlices);

// bind partitions and grouping table
homogeneous_apply_refs_sized<numElements>([&groupingTable](auto& x) {
analysis_task_parsers::bindExternalIndicesPartition(x, &groupingTable);
return true;
},
task);
task);

[](Task& task, void (Task::*processingFunction)(Grouping, Associated...), Grouping g, std::tuple<std::decay_t<Associated>...>& at) {
std::invoke(processingFunction, task, g, std::get<std::decay_t<Associated>>(at)...);
}(task, processingFunction, slice.groupingElement(), associatedSlices);
std::invoke(processingFunction, task, slice.groupingElement(), associatedSlices...);
}(slice.template prepareArgument<std::decay_t<Associated>>()...);
}
} else {
// bind partitions and grouping table
Expand Down
17 changes: 17 additions & 0 deletions Framework/Core/include/Framework/ArrowTableSlicingCache.h
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,19 @@ struct ArrowTableSlicingCache {
int getCachePosSortedFor(Entry const& bindingKey) const;
int getCachePosUnsortedFor(Entry const& bindingKey) const;

// locate an enabled entry of the given kind; throws if the key is in the other
// cache, in neither, or disabled
int locateSorted(Entry const& bindingKey) const;
int locateUnsorted(Entry const& bindingKey) const;

// positions already located, by a key the caller makes from the table type
// and the index column (see soa::getSliceInfoFor); -1 if not known yet. The
// entry lists only change in setCaches, which forgets them.
int knownPosition(uint64_t key) const;
int knownPositionUnsorted(uint64_t key) const;
void rememberPosition(uint64_t key, int pos) const;
void rememberPositionUnsorted(uint64_t key, int pos) const;

// get slice from cache for a given value
SliceInfoPtr getCacheFor(Entry const& bindingKey) const;
SliceInfoUnsortedPtr getCacheUnsortedFor(Entry const& bindingKey) const;
Expand All @@ -114,6 +127,10 @@ struct ArrowTableSlicingCache {
std::pair<arrow::Table const*, std::shared_ptr<arrow::Table>> emptySlice{nullptr, nullptr};

static void validateOrder(Entry const& bindingKey, std::shared_ptr<arrow::Table> const& input);

private:
mutable std::vector<std::pair<uint64_t, int>> mKnownPositions;
mutable std::vector<std::pair<uint64_t, int>> mKnownPositionsUnsorted;
};
} // namespace o2::framework

Expand Down
51 changes: 25 additions & 26 deletions Framework/Core/include/Framework/GroupSlicer.h
Original file line number Diff line number Diff line change
Expand Up @@ -160,11 +160,10 @@ struct GroupSlicer {
return *this;
}

auto associatedTables()
{
return std::make_tuple(prepareArgument<A>()...);
}

/// The associated table A1 for the current grouping element: a slice for
/// tables related to the grouping table, otherwise the full table. Slices are
/// returned as prvalues, so that the caller can bind them without a copy;
/// their internal indices still need to be bound to the full table.
template <soa::is_smallgroups A1>
requires(o2::soa::relatedByIndex<std::decay_t<G>, std::decay_t<A1>>() && soa::is_filtered_table<A1>)
auto prepareArgument()
Expand All @@ -179,24 +178,22 @@ struct GroupSlicer {
}
// generic split
auto selection = sliceInfosUnsorted[index].getSliceFor(pos);
// intersect selections
o2::soa::SelectionVector s;
if (selections[index]->empty()) {
if (!selection.empty()) {
std::copy(selection.begin(), selection.end(), std::back_inserter(s));
}
} else {
if (!selection.empty()) {
if constexpr (std::decay_t<A1>::applyFilters) {
if constexpr (std::decay_t<A1>::applyFilters) {
// a selection of sorted, unique rows that is as long as the full table
// selects every row: the intersection is then the group itself
if (!selections[index]->empty() && std::ssize(*selections[index]) != originalTable.tableSize()) {
// intersect with the filter of the full table: the result is a new selection
o2::soa::SelectionVector s;
if (!selection.empty()) {
std::set_intersection(selection.begin(), selection.end(), selections[index]->begin(), selections[index]->end(), std::back_inserter(s));
} else {
std::copy(selection.begin(), selection.end(), std::back_inserter(s));
}
auto range = soa::unsortedSliceRange(originalTable.asArrowTableRef(), s);
return soa::makeTableOn<std::decay_t<A1>>(std::move(range), originalTable, std::move(s));
}
}
std::decay_t<A1> typedTable{{originalTable.asArrowTableRef()}, std::move(s)};
typedTable.bindInternalIndicesTo(&originalTable);
return typedTable;
// no filter to apply, or one that selects every row: view the rows of the group in the slicing cache,
// which lives throughout the process call, instead of copying them
return soa::makeTableOn<std::decay_t<A1>>(soa::unsortedSliceRange(originalTable.asArrowTableRef(), selection), originalTable, selection);
}

template <soa::is_filtered_table A1>
Expand All @@ -219,6 +216,10 @@ struct GroupSlicer {
uint64_t offset = oc.first;
auto count = oc.second;
auto groupedElementsTable = originalTable.asArrowTableRef().slice({offset, count});
if (count == 0) {
// an empty group selects no rows; starts[index] stays valid for the next groups
return soa::makeTableOn<std::decay_t<A1>>(std::move(groupedElementsTable), originalTable, soa::SelectionVector{});
}

// for each grouping element we need to slice the selection vector
auto start_iterator = std::lower_bound(starts[index], selections[index]->end(), offset);
Expand All @@ -230,9 +231,7 @@ struct GroupSlicer {
return idx - static_cast<int64_t>(offset);
});

std::decay_t<A1> typedTable{{groupedElementsTable}, std::move(slicedSelection)};
typedTable.bindInternalIndicesTo(&originalTable);
return typedTable;
return soa::makeTableOn<std::decay_t<A1>>(std::move(groupedElementsTable), originalTable, std::move(slicedSelection));
}

template <soa::is_table A1>
Expand All @@ -252,14 +251,14 @@ struct GroupSlicer {
}
// optimized split
auto [offset, count] = sliceInfos[index].getSliceFor(pos);
auto groupedElementsTable = originalTable.rawSlice(offset, offset + count - 1);
groupedElementsTable.bindInternalIndicesTo(&originalTable);
return groupedElementsTable;
return soa::makeTableOn<std::decay_t<A1>>(originalTable.asArrowTableRef().slice({static_cast<uint64_t>(offset), static_cast<int64_t>(count)}), originalTable);
}

/// Tables not related to the grouping table are the same for every grouping
/// element, so the full table is returned by reference instead of a copy.
template <soa::is_table A1>
requires(!o2::soa::relatedByIndex<std::decay_t<G>, std::decay_t<A1>>() && !soa::is_smallgroups<A1>)
auto prepareArgument()
A1& prepareArgument()
{
return std::get<A1>(*mAt);
}
Expand Down
Loading