HuaHuaY commented on code in PR #55897:
URL: https://github.com/apache/arrow/pull/55897#discussion_r4780717981
##########
cpp/src/parquet/decoder.cc:
##########
@@ -1325,30 +1319,48 @@ class DictByteArrayDecoderImpl : public
DictDecoderImpl<ByteArrayType> {
const int values_to_decode = num_values - null_count;
int values_decoded = 0;
int num_indices = 0;
- int pos_indices = 0;
+ auto refill_indices = [&]() {
+ const int batch_size =
+ std::min<int>(kBufferSize, values_to_decode - values_decoded);
+ num_indices = idx_decoder_.GetBatch(indices, batch_size);
+ if (ARROW_PREDICT_FALSE(num_indices < 1)) {
+ return Status::Invalid("Invalid number of indices: ", num_indices);
+ }
+ return Status::OK();
+ };
+ auto append_indices = [&](const int32_t* batch, int length) {
+ for (int i = 0; i < length; ++i) {
+ const auto index = batch[i];
+ RETURN_NOT_OK(IndexInBounds(index));
+ const auto& val = dict_values[index];
+ RETURN_NOT_OK(helper->AppendValue(val.ptr,
static_cast<int32_t>(val.len)));
+ }
+ values_decoded += length;
+ return Status::OK();
+ };
+ if (null_count == 0) {
+ while (values_decoded < num_values) {
+ RETURN_NOT_OK(refill_indices());
+ RETURN_NOT_OK(append_indices(indices, num_indices));
+ }
+ *out_num_values = values_decoded;
+ return Status::OK();
+ }
+
+ int pos_indices = 0;
auto visit_bit_run = [&](int64_t position, int64_t length, bool valid) {
if (valid) {
while (length > 0) {
if (num_indices == pos_indices) {
- // Refill indices buffer
- const auto max_batch_size =
- std::min<int32_t>(kBufferSize, values_to_decode -
values_decoded);
- num_indices = idx_decoder_.GetBatch(indices, max_batch_size);
- if (ARROW_PREDICT_FALSE(num_indices < 1)) {
- return Status::Invalid("Invalid number of indices: ",
num_indices);
- }
+ RETURN_NOT_OK(refill_indices());
pos_indices = 0;
}
- const auto batch_size = std::min<int64_t>(num_indices -
pos_indices, length);
- for (int64_t j = 0; j < batch_size; ++j) {
- const auto index = indices[pos_indices++];
Review Comment:
I suspect the issue with the original code lies here: `pos_indices` is a
variable defined outside the lambda, and it is updated only after calls to
`helper->AppendValue`.
I believe that by switching to `indices[pos_indices + j]`—while incrementing
`pos_indices` by `batch_size` at the end—we should be able to achieve a similar
optimization.
--
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]