Skip to content

Commit

Permalink
more performance optimizations for tuple data appends
Browse files Browse the repository at this point in the history
  • Loading branch information
lnkuiper committed Jul 25, 2023
1 parent 7b8cca4 commit a7e35db
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 5 deletions.
2 changes: 1 addition & 1 deletion src/common/types/row/tuple_data_allocator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -243,7 +243,7 @@ void TupleDataAllocator::InitializeChunkStateInternal(TupleDataPinState &pin_sta
if (recompute && pin_state.properties != TupleDataPinProperties::ALREADY_PINNED) {
const auto new_base_heap_ptr = GetBaseHeapPointer(pin_state, part);
if (part.base_heap_ptr != new_base_heap_ptr) {
lock_guard<mutex> guard(part.lock);
lock_guard<mutex> guard(*part.lock);
const auto old_base_heap_ptr = part.base_heap_ptr;
if (old_base_heap_ptr != new_base_heap_ptr) {
Vector old_heap_ptrs(
Expand Down
6 changes: 4 additions & 2 deletions src/common/types/row/tuple_data_segment.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ void SwapTupleDataChunkPart(TupleDataChunkPart &a, TupleDataChunkPart &b) {
std::swap(a.base_heap_ptr, b.base_heap_ptr);
std::swap(a.total_heap_size, b.total_heap_size);
std::swap(a.count, b.count);
// Cannot swap the lock, but not needed as move constructor only happens during append, lock only needed for scans
std::swap(a.lock, b.lock);
}

TupleDataChunkPart::TupleDataChunkPart(TupleDataChunkPart &&other) noexcept {
Expand All @@ -27,7 +27,7 @@ TupleDataChunkPart &TupleDataChunkPart::operator=(TupleDataChunkPart &&other) no
return *this;
}

TupleDataChunk::TupleDataChunk() : count(0) {
TupleDataChunk::TupleDataChunk() : count(0), lock(make_unsafe_uniq<mutex>()) {
parts.reserve(2);
}

Expand All @@ -36,6 +36,7 @@ static inline void SwapTupleDataChunk(TupleDataChunk &a, TupleDataChunk &b) noex
std::swap(a.row_block_ids, b.row_block_ids);
std::swap(a.heap_block_ids, b.heap_block_ids);
std::swap(a.count, b.count);
std::swap(a.lock, b.lock);
}

TupleDataChunk::TupleDataChunk(TupleDataChunk &&other) noexcept {
Expand All @@ -53,6 +54,7 @@ void TupleDataChunk::AddPart(TupleDataChunkPart &&part, const TupleDataLayout &l
if (!layout.AllConstant() && part.total_heap_size > 0) {
heap_block_ids.insert(part.heap_block_index);
}
part.lock = lock.get();
parts.emplace_back(std::move(part));
}

Expand Down
6 changes: 4 additions & 2 deletions src/include/duckdb/common/types/row/tuple_data_segment.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,8 @@ struct TupleDataChunkPart {
uint32_t total_heap_size;
//! Tuple count for this chunk part
uint32_t count;
//! Lock for recomputing heap pointers
mutex lock;
//! Lock for recomputing heap pointers (owned by TupleDataChunk)
mutex *lock;
};

struct TupleDataChunk {
Expand Down Expand Up @@ -78,6 +78,8 @@ struct TupleDataChunk {
perfect_set_t heap_block_ids;
//! Tuple count for this chunk
idx_t count;
//! Lock for recomputing heap pointers
unsafe_unique_ptr<mutex> lock;
};

struct TupleDataSegment {
Expand Down

0 comments on commit a7e35db

Please sign in to comment.