This is an automated email from the ASF dual-hosted git repository.
Gabriel39 pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/doris.git
The following commit(s) were added to refs/heads/master by this push:
new 4e374d4987b [opt](parquet) Speed up BOOLEAN decoding in the V2 reader
(#70928)
4e374d4987b is described below
commit 4e374d4987bd98ed7ee173d8dd1102c0f6d92f4c
Author: HappenLee <[email protected]>
AuthorDate: Fri Dec 4 14:29:09 2026 +0800
[opt](parquet) Speed up BOOLEAN decoding in the V2 reader (#70928)
### Background
The native Parquet V2 reader expands PLAIN BOOLEAN values from one bit
to one byte, in batches of up to 128 values. The fixed-value consumer
accepts contiguous spans of these bytes.
### What problem does this PR solve?
Issue Number: None
Related PR: None
PR Type: Performance
Problem Summary:
Dense PLAIN BOOLEAN reads process every value again after batch
unpacking. Passing the unpacked spans directly to the consumer removes
that work and speeds up the decoder on both ARM64 and AVX2 builds.
### Details
- **Why it was slow:** The decoder checked the scratch-buffer cursor for
every value and copied each value into a stack array before handing the
array to the consumer.
- **Optimization:** Refill the existing scratch buffer as needed and
pass each available contiguous span directly to the consumer. Advance
the cursor once per span and check the available input once per request.
`UnpackBatch()` selects the underlying bit-unpacking path.
- **Results:** Median of 11 measured rounds on one pinned CPU core. Each
run decodes 100,000 dense, null-free PLAIN BOOLEAN values in 4,096-value
requests. Times cover the in-memory decoder and its output consumer. The
x86-64 runs used `-O3 -mavx2` with PDEP enabled. The ARM64 runs used
`-O3 -march=armv8-a`. [ARM64 benchmark
run](https://github.com/HappenLee/incubator-doris/actions/runs/45322631720)
| CPU | Compiler | Before | After | Speedup |
|---|---|---:|---:|---:|
| ARM64 Neoverse N2 | Clang 18.1 | 75.84 us | 15.76 us | 4.81x |
| ARM64 Neoverse N2 | GCC 14.2 | 78.94 us | 22.52 us | 3.50x |
| Intel Xeon Platinum 8457C | Clang 20.1 | 102.08 us | 30.78 us | 3.32x
|
| Intel Xeon Platinum 8457C | GCC 15.1 | 88.93 us | 28.86 us | 3.08x |
- **Applicability and cost:** Applies to Parquet V2 PLAIN BOOLEAN
fixed-value reads on all builds. Unaligned requests may be delivered in
multiple spans under the existing consumer contract. The decoder reuses
its 128-byte scratch buffer.
### Testing
- Four Parquet V2 BOOLEAN tests passed in a local non-AVX2 ASAN build
before rebasing, including the new regression test for unaligned
requests across refill boundaries and truncated input.
- Isolated ARM64 and AVX2 decoder tests checked decoded bytes, unaligned
input, and split requests. An isolated AVX2 ASAN test of the unified
code passed with PDEP enabled and disabled, including recovery after
rejecting a truncated read.
### Release note
None
### Check List (For Author)
- Behavior changed: No
- Does this need documentation: No
- Pre-submission status: Partially verified: the full local AVX2 BE
unit-test binary is still building.
### AI Disclosure
- Tool: Codex (GPT-6)
- Generated: the implementation, regression test, benchmark harness, and
PR description
- Human review: not stated
---
.../parquet/reader/native/bool_plain_decoder.cpp | 29 ++++++++++++----------
be/test/format_v2/parquet/native_decoder_test.cpp | 25 +++++++++++++++++++
2 files changed, 41 insertions(+), 13 deletions(-)
diff --git a/be/src/format_v2/parquet/reader/native/bool_plain_decoder.cpp
b/be/src/format_v2/parquet/reader/native/bool_plain_decoder.cpp
index 06e4b239f3a..20ddba99b30 100644
--- a/be/src/format_v2/parquet/reader/native/bool_plain_decoder.cpp
+++ b/be/src/format_v2/parquet/reader/native/bool_plain_decoder.cpp
@@ -20,7 +20,6 @@
#include <glog/logging.h>
#include <algorithm>
-#include <array>
#include "core/column/column_vector.h"
#include "core/types.h"
@@ -29,19 +28,23 @@
namespace doris::format::parquet::native {
Status BoolPlainDecoder::decode_fixed_values(size_t num_values,
ParquetFixedValueConsumer&
consumer) {
- std::array<uint8_t, UNPACKED_BUFFER_LEN> values;
- size_t decoded = 0;
- while (decoded < num_values) {
- const size_t batch_size = std::min(values.size(), num_values -
decoded);
- for (size_t row = 0; row < batch_size; ++row) {
- bool value = false;
- if (UNLIKELY(!_decode_value(&value))) {
- return Status::IOError("Can't read enough booleans in plain
decoder");
- }
- values[row] = static_cast<uint8_t>(value);
+ const size_t available = num_unpacked_values_ - unpacked_value_idx_ +
+ static_cast<size_t>(bool_values_.bytes_left()) *
8;
+ if (UNLIKELY(num_values > available)) {
+ return Status::IOError("Can't read enough booleans in plain decoder");
+ }
+ while (num_values != 0) {
+ if (unpacked_value_idx_ == num_unpacked_values_) {
+ num_unpacked_values_ =
+ bool_values_.UnpackBatch(1, UNPACKED_BUFFER_LEN,
unpacked_values_);
+ unpacked_value_idx_ = 0;
}
- RETURN_IF_ERROR(consumer.consume(values.data(), batch_size,
sizeof(uint8_t)));
- decoded += batch_size;
+ const auto* values = unpacked_values_ + unpacked_value_idx_;
+ const size_t batch_size = std::min(
+ num_values, static_cast<size_t>(num_unpacked_values_ -
unpacked_value_idx_));
+ unpacked_value_idx_ += batch_size;
+ RETURN_IF_ERROR(consumer.consume(values, batch_size, sizeof(uint8_t)));
+ num_values -= batch_size;
}
return Status::OK();
}
diff --git a/be/test/format_v2/parquet/native_decoder_test.cpp
b/be/test/format_v2/parquet/native_decoder_test.cpp
index 722e45b36b7..686d22e1d60 100644
--- a/be/test/format_v2/parquet/native_decoder_test.cpp
+++ b/be/test/format_v2/parquet/native_decoder_test.cpp
@@ -2946,6 +2946,31 @@ TEST(ParquetV2NativeDecoderTest,
NestedReadersRejectRleAndBitPackedLevelsAboveMa
}
}
+TEST(ParquetV2NativeDecoderTest, PlainBooleanDenseBatchesKeepUnreadBits) {
+ std::vector<uint8_t> packed(33);
+ for (size_t i = 0; i < packed.size(); ++i) {
+ packed[i] = static_cast<uint8_t>(37 * i + 21);
+ }
+ std::unique_ptr<Decoder> decoder;
+ ASSERT_TRUE(
+ Decoder::get_decoder(tparquet::Type::BOOLEAN,
tparquet::Encoding::PLAIN, decoder).ok());
+ Slice data(reinterpret_cast<char*>(packed.data()), packed.size());
+ ASSERT_TRUE(decoder->set_data(&data).ok());
+
+ CaptureFixedConsumer consumer;
+ for (size_t batch : {137, 5, 115}) {
+ ASSERT_TRUE(decoder->decode_fixed_values(batch, consumer).ok());
+ }
+ const auto values = consumer.values<uint8_t>();
+ ASSERT_EQ(values.size(), 257);
+ for (size_t i = 0; i < values.size(); ++i) {
+ EXPECT_EQ(values[i], (packed[i / 8] >> (i % 8)) & 1) << "index " << i;
+ }
+ CaptureFixedConsumer truncated;
+ EXPECT_FALSE(decoder->decode_fixed_values(8, truncated).ok());
+ EXPECT_TRUE(truncated.bytes.empty());
+}
+
TEST(ParquetV2NativeDecoderTest, TruncatedBooleanStreamsFailWhileSkipping) {
std::unique_ptr<Decoder> decoder;
ASSERT_TRUE(
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]