From 21a9960acfc51b1ce87b1bfbd87cd9e2d01fd444 Mon Sep 17 00:00:00 2001 From: Yuan Date: Tue, 30 Sep 2025 15:01:59 +0100 Subject: [PATCH 1/2] [VL] Reduce memcpy in c2r We always fill the buffer with 0 so it's no necessary to keep the old content when doing allocation in C2R Signed-off-by: Yuan --- .../operators/serializer/VeloxColumnarToRowConverter.cc | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-) diff --git a/cpp/velox/operators/serializer/VeloxColumnarToRowConverter.cc b/cpp/velox/operators/serializer/VeloxColumnarToRowConverter.cc index 9a474f8141c6..b913765dc19a 100644 --- a/cpp/velox/operators/serializer/VeloxColumnarToRowConverter.cc +++ b/cpp/velox/operators/serializer/VeloxColumnarToRowConverter.cc @@ -57,14 +57,9 @@ void VeloxColumnarToRowConverter::refreshStates(facebook::velox::RowVectorPtr ro numRows_ = endRow - startRow; } - if (nullptr == veloxBuffers_) { - veloxBuffers_ = velox::AlignedBuffer::allocate(totalMemorySize, veloxPool_.get()); - } else if (veloxBuffers_->capacity() < totalMemorySize) { - velox::AlignedBuffer::reallocate(&veloxBuffers_, totalMemorySize); + if (nullptr == veloxBuffers_ || veloxBuffers_->capacity() < totalMemorySize) { + veloxBuffers_ = velox::AlignedBuffer::allocate(totalMemorySize, veloxPool_.get(), 0); } - - bufferAddress_ = veloxBuffers_->asMutable(); - memset(bufferAddress_, 0, sizeof(int8_t) * totalMemorySize); } void VeloxColumnarToRowConverter::convert(std::shared_ptr cb, int64_t startRow) { From 6dbe60e31337e856aa7767f6bba3e4c5b6d9e898 Mon Sep 17 00:00:00 2001 From: Yuan Date: Mon, 13 Oct 2025 11:47:31 -0400 Subject: [PATCH 2/2] fix Signed-off-by: Yuan --- .../operators/serializer/VeloxColumnarToRowConverter.cc | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/cpp/velox/operators/serializer/VeloxColumnarToRowConverter.cc b/cpp/velox/operators/serializer/VeloxColumnarToRowConverter.cc index b913765dc19a..f8977ee1bda9 100644 --- a/cpp/velox/operators/serializer/VeloxColumnarToRowConverter.cc +++ b/cpp/velox/operators/serializer/VeloxColumnarToRowConverter.cc @@ -58,8 +58,11 @@ void VeloxColumnarToRowConverter::refreshStates(facebook::velox::RowVectorPtr ro } if (nullptr == veloxBuffers_ || veloxBuffers_->capacity() < totalMemorySize) { - veloxBuffers_ = velox::AlignedBuffer::allocate(totalMemorySize, veloxPool_.get(), 0); + veloxBuffers_ = velox::AlignedBuffer::allocate(totalMemorySize, veloxPool_.get()); } + + bufferAddress_ = veloxBuffers_->asMutable(); + memset(bufferAddress_, 0, sizeof(int8_t) * totalMemorySize); } void VeloxColumnarToRowConverter::convert(std::shared_ptr cb, int64_t startRow) {