GH-55399: [C++][Parquet] Minor optimize level counting with CountLevels #55408
All Vouch review confidence checks passed
Residual risk 0.18 = Change Risk (0.43) × (1 − Review Confidence (0.57)).
Review depth and reviewer attention state are adequate.
Model 1 · Change Risk (XGBoost)
Score: 0.43 · 368 lines diff across 4 files
Model 2 · Review Depth (DistilBERT)
Depth Score: 0.17 · 1 substantive comment(s)
Model 3 · Review Timing & Attention
Session adequacy: 100% · Reviewer familiarity: 35%
Bedrock Claude 3 · Risk Narration
(disconnected)
Groq Risk Narration
AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
Model 1 · Change Risk Attribution
SHAP Weights
Diff Size
diff_size
0.354
Shallow Review Depth
shallow_review_depth
0.289
Real PR Conversation Timeline
1 comments
"Review active on #55408"
general
weight: 0.35
pitrou
Rationale for this change
std::countoverint16_tlevels widens every comparison result to a 64-bit accumulator, preventing efficient 16-bit lane vectorization. Accumulating inuint16_tchunks keeps the reduction in 16-bit lanes without overflowing:1. x86: https://godbolt.org/z/Gqc7fxe55
2. ARM: https://godbolt.org/z/sGhG8crYa
3. Fast-path vs out-of-line chunked fallback (
-O2x86 AVX2 & ARM NEON): https://godbolt.org/z/rvobWjrfaBefore x86:
After x86:
Before ARM:
After ARM:
Some notes:
1. Inputs larger than
uint16_t::max()(65535) use an out-of-line chunked fallback (CountLevelsIfChunked), so the common single-page path avoids outer-loop LICM hoisting of vector broadcasts (vpbroadcastw+vzeroupperon x86 AVX2 /dup.8hon NEON) on short inputs.2. Non-template
inlinewrappers (CountLevelsandCountLevelsGreaterEqual) are provided on top ofCountLevelsIfto keep call sites concise and ensure a single shared closure type per wrapper across translation units (so the linker ODR-deduplicatesCountLevelsIfChunkedto one copy per wrapper across physical-type template instantiations and TUs).3. Optimizes both read and write paths (though level counting is only a small part of end-to-end Parquet I/O).
What changes are included in this PR?
CountLevels,CountLevelsGreaterEqual,CountLevelsIf, and out-of-line fallbackCountLevelsIfChunkedincpp/src/parquet/level_comparison_internal.h.CountLevels/CountLevelsGreaterEqualincpp/src/parquet/column_reader.cc,cpp/src/parquet/column_writer.cc, andcpp/src/parquet/file_reader.cc.cpp/src/parquet/level_conversion_test.cccovering predicates, tail lengths, anduint16_t::max()chunk boundaries.Are these changes tested?
Yes, unit tests in
cpp/src/parquet/level_conversion_test.ccand covered by existing Parquet reader/writer tests.Are there any user-facing changes?
No
Was AI used for this PR?
PR code and description written by:
Reviewed before submission by: