Repository navigation
GH-55896: [C++][Parquet] Restore a fast path for null-free dictionary-encoded BYTE_ARRAY batches - #55897
Conversation
|
@ursabot please benchmark lang=C++ |
|
Benchmark runs are scheduled for commit ecc4d49. Watch https://buildkite.com/apache-arrow and https://conbench.arrow-dev.org for updates. A comment will be posted here when the runs are complete. |
Benchmark result is not pasted here automatically due to some failures. I asked AI to help me analyze them and got them back as below. The results support the speedup in 20 of 24 comparisons (83%) across three runners and four batch sizes. The only exception was Binary decoding on AMD M5. Similar benchmarks outside the changed path also slowed on M5, so it’s unclear how much of that slowdown came from the patch. Buildkite results for #55897Base 65,536 values across runners
M5 dictionary-to-dense resultsBoth builds used GCC 15.3 Release on Xeon 8259CL. They ran on separate EC2 instances.
Individual Binary measurements at 65,536 values, in MiB/s:
M5 controls from the same logs
BinaryView improved on all three runners. On M5, Binary dictionary-to-dense declined more than the same-size controls at every batch size. These separate-instance runs leave the cause unresolved. |
| } | ||
| 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++]; |
There was a problem hiding this comment.
I suspect part of the issue is that pos_indices is captured by reference. In the local build, it is written back before each call to helper->AppendValue and reloaded on the next iteration. The loop also reloads the index buffer and dictionary pointers.
I believe that by switching to
const auto* batch = indices + pos_indices;
const auto* const run_dict = dict_values;
auto* const run_helper = helper;
for (int64_t j = 0; j < batch_size; ++j) {
const auto index = batch[j];
RETURN_NOT_OK(IndexInBounds(index));
const auto& val = run_dict[index];
RETURN_NOT_OK(run_helper->AppendValue(val.ptr, static_cast<int32_t>(val.len)));
}
pos_indices += static_cast<int>(batch_size);and mark ArrowBinaryHelper<ByteArrayType, ::arrow::BinaryType>::AppendValue ARROW_FORCE_INLINE
, we should be able to achieve a similar optimization.
Or, keeping batch[j] and ARROW_FORCE_INLINE on AppendValue, we may be able to mark the lambda always_inline instead of adding the run_dict and run_helper variables.
auto visit_bit_run = [&](int64_t position, int64_t length, bool valid)
__attribute__((always_inline)) {There was a problem hiding this comment.
Given that the changes in this PR already yield performance improvements, these comments serve merely to explain the reasons behind those gains. They may also serve as a reference should anyone wish to simplify the code in the future. I have decided to approve the original PR.
Rationale for this change
While testing the Paimon C++ upgrade from Arrow 17 to 26, we found that scanning dictionary-encoded string columns slowed down at larger batch sizes. Performance results in apache/paimon-cpp#598 The dense Parquet decoder already treats a null-free batch as a single valid run, but tracks both the remaining run length and a cursor into the index buffer. For these batches, every index read can be consumed immediately.
What changes are included in this PR?
Handle
null_count == 0insideDictByteArrayDecoderImpl::DecodeArrowDense. Fill the existing 1,024-index buffer and append all indices returned by each read. Batches with nulls continue to useVisitBitRuns, retaining unused indices across null runs. Both paths share the index refill, dictionary bounds check, and value append logic.Are these changes tested?
Existing
DictEncoding.CheckDecodeArrowUsingDenseBuildercoverage checks the output values and decoded count for 10,000 values with zero, mixed, and all nulls across Binary, LargeBinary, BinaryView and their string counterparts.DictEncoding.CheckDecodeArrowNonNullDenseBuilderexercises the explicit non-null entry point across multiple index-buffer refills. Both validate the resulting arrays. The existing tests cover this change.Are there any user-facing changes?
Reading null-free batches of dictionary-encoded Parquet strings or binary values into dense Arrow arrays can be faster.
The table compares the original and optimized loops in Clang 17 Release builds. Each result is the median across runs.
Was AI used for this PR?
OpenAI Codex wrote the implementation and PR description. The contributor reviewed the code before submission.
PR code and description written by:
Reviewed before submission by: