Skip to content

GH-55896: [C++][Parquet] Restore a fast path for null-free dictionary-encoded BYTE_ARRAY batches - #55897

Merged
HuaHuaY merged 1 commit into
apache:mainfrom
zjw1111:codex/parquet-null-free-dictionary-loop
Dec 3, 2026
Merged

HuaHuaY merged 1 commit into
apache:mainfrom
zjw1111:codex/parquet-null-free-dictionary-loop

Conversation

@zjw1111

@zjw1111 zjw1111 commented Dec 2, 2026 •

Copy link
Copy Markdown
Contributor

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 == 0 inside DictByteArrayDecoderImpl::DecodeArrowDense. Fill the existing 1,024-index buffer and append all indices returned by each read. Batches with nulls continue to use VisitBitRuns, 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.CheckDecodeArrowUsingDenseBuilder coverage 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.CheckDecodeArrowNonNullDenseBuilder exercises 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.

Benchmark Batch size Runs per build Before After Change
Single-threaded Parquet scan of the four files in #55896 10,000 rows 3 33.34 s 28.55 s 14.37% less time
Binary dictionary decode 65,536 values 7 189.68 MiB/s 222.38 MiB/s 17.24% higher throughput
BinaryView dictionary decode 65,536 values 7 165.09 MiB/s 180.14 MiB/s 9.11% higher throughput

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:

  • Human
  • AI

Reviewed before submission by:

  • Human
  • AI
  • Not reviewed

@wgtmac

wgtmac commented Dec 2, 2026

Copy link
Copy Markdown
Member

@ursabot please benchmark lang=C++

@rok

rok commented Dec 2, 2026

Copy link
Copy Markdown
Member

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.

@wgtmac wgtmac left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

+1

Thanks @zjw1111 for fixing this!

@wgtmac

wgtmac commented Dec 3, 2026

Copy link
Copy Markdown
Member

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 #55897

Base 8f02a9c → PR head ecc4d49. Throughput is in MiB/s, reported as the median of six repetitions of DecodeArrow_Dense with no nulls. All three base logs contain the measurements below.

65,536 values across runners

Runner Binary dictionary → dense BinaryView dictionary → dense
AMD64 C6a 312.6 → 349.7 (+11.9%) 312.7 → 330.9 (+5.8%)
AMD64 M5 197.1 → 191.1 (−3.0%) 210.8 → 220.7 (+4.7%)
Apple M1 291.5 → 343.7 (+17.9%) 292.0 → 333.2 (+14.1%)

M5 dictionary-to-dense results

Both builds used GCC 15.3 Release on Xeon 8259CL. They ran on separate EC2 instances.

Values Binary BinaryView
1,024 223.0 → 211.9 (−5.0%) 226.0 → 233.3 (+3.2%)
4,096 215.0 → 203.5 (−5.3%) 226.3 → 234.8 (+3.8%)
32,768 203.0 → 193.5 (−4.7%) 214.3 → 224.0 (+4.5%)
65,536 197.1 → 191.1 (−3.0%) 210.8 → 220.7 (+4.7%)

Individual Binary measurements at 65,536 values, in MiB/s:

  • Base — 196.85, 197.05, 196.84, 197.29, 197.11, 197.17
  • PR — 191.63, 190.92, 191.44, 190.95, 190.77, 191.31

M5 controls from the same logs

Values Plain Binary → dense Plain BinaryView → dense Binary dictionary → dictionary output
1,024 633.6 → 619.3 (−2.3%) 293.6 → 289.3 (−1.5%) 152.8 → 148.5 (−2.8%)
4,096 492.8 → 486.4 (−1.3%) 288.4 → 284.6 (−1.3%) 146.2 → 142.7 (−2.4%)
32,768 453.2 → 446.2 (−1.5%) 280.8 → 276.2 (−1.6%) 119.0 → 116.3 (−2.3%)
65,536 449.8 → 443.1 (−1.5%) 278.0 → 274.1 (−1.4%) 117.8 → 115.8 (−1.7%)
Control set Matched cases Median change Spread
Arrow throughput cases outside Parquet and Dataset 3,824 −0.6% P10–P90: −6.1% to +3.2%
Parquet encoding cases outside the affected paths 478 −1.8% P10–P90: −4.9% to +0.1%
Closest decoder controls, including explicit non-null variants 24 −1.7% Full range: −2.8% to −1.2%

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++];

@HuaHuaY HuaHuaY Dec 3, 2026 •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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)) {

@HuaHuaY HuaHuaY Dec 3, 2026 •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@HuaHuaY
HuaHuaY merged commit 461158a into apache:main Dec 3, 2026
64 of 108 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[C++][Parquet] Restore a fast path for null-free dictionary-encoded BYTE_ARRAY batches

4 participants