marin-ma commented on code in PR #6869:
URL: https://github.com/apache/incubator-gluten/pull/6869#discussion_r1744699322
##########
cpp/core/shuffle/Payload.cc:
##########
@@ -186,45 +186,45 @@ arrow::Result<std::unique_ptr<BlockPayload>>
BlockPayload::fromBuffers(
std::vector<std::shared_ptr<arrow::Buffer>> buffers,
const std::vector<bool>* isValidityBuffer,
arrow::MemoryPool* pool,
- arrow::util::Codec* codec) {
+ arrow::util::Codec* codec,
+ std::shared_ptr<arrow::Buffer> compressed) {
if (payloadType == Payload::Type::kCompressed) {
Timer compressionTime;
compressionTime.start();
// Compress.
- // Compressed buffer layout: | buffer1 compressedLength | buffer1
uncompressedLength | buffer1 | ...
- const auto metadataLength = sizeof(int64_t) * 2 * buffers.size();
- int64_t totalCompressedLength =
- std::accumulate(buffers.begin(), buffers.end(), 0LL, [&](auto sum,
const auto& buffer) {
- if (!buffer) {
- return sum;
- }
- return sum + codec->MaxCompressedLen(buffer->size(), buffer->data());
- });
- const auto maxCompressedLength = metadataLength + totalCompressedLength;
- ARROW_ASSIGN_OR_RAISE(
- std::shared_ptr<arrow::ResizableBuffer> compressed,
arrow::AllocateResizableBuffer(maxCompressedLength, pool));
-
- auto output = compressed->mutable_data();
+ auto maxLength = maxCompressedLength(buffers, codec);
+ std::shared_ptr<arrow::Buffer> compressedBuffer;
+ uint8_t* output;
+ if (compressed) {
+ ARROW_RETURN_IF(
+ compressed->size() < maxLength,
+ arrow::Status::Invalid(
+ "Compressed buffer length < maxCompressedLength. (",
compressed->size(), " vs ", maxLength, ")"));
+ output = const_cast<uint8_t*>(compressed->data());
+ } else {
+ ARROW_ASSIGN_OR_RAISE(compressedBuffer,
arrow::AllocateResizableBuffer(maxLength, pool));
Review Comment:
We hold the original evicted buffer for uncompressed payload. There are no
extra copy.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]