Optimize byte-array dictionary gathering in arrow-row #12113
All Vouch review confidence checks passed
Residual risk 0.16 = Change Risk (0.40) × (1 − Review Confidence (0.60)).
Review depth and reviewer attention state are adequate.
Model 1 · Change Risk (XGBoost)
Score: 0.40 · 301 lines diff across 3 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.342
Shallow Review Depth
shallow_review_depth
0.289
Real PR Conversation Timeline
1 comments
"Review active on #12113"
general
weight: 0.35
JonSnow1807
Which issue does this PR close?
Closes #12053.
Rationale for this change
The sparse-dictionary encoding path gathers one dictionary value per input row before encoding. The current gather performs a dynamic MutableArrayData extension for every key, which adds overhead for common string and binary dictionaries.
What changes are included in this PR?
Add typed gather implementations for Utf8, LargeUtf8, Binary, and LargeBinary dictionary values. These build the offsets, value buffer, and validity bitmap directly.
Other value types continue to use the generic MutableArrayData implementation. Offset growth is checked so that overflow continues to reach the existing fallback. The dictionary-gather thresholds are unchanged.
Are these changes tested?
I’ve simplified test_gather_dictionary_byte_values to use StringArray, since the string and binary variants share the same gather implementation. The test still covers sliced keys, null keys, and keys that reference null dictionary values.
All 110 arrow-row library tests pass. Workspace tests, workspace Clippy checks, formatting, and spelling checks also pass.
Performance was measured using the existing prepared 8,192-row string-dictionary benchmark on an Intel Xeon E5-2673 v4, Linux x86_64, with Rust 1.99.1. This benchmark cycles through contiguous key chunks.
Two paired Criterion runs used 50 samples, a one-second warmup, and a three-second measurement period. Execution order was reversed for the second pair. The table reports the average of the two runs’ mean estimates.
| Dictionary values | Before | After | Change in mean time |
| ---: | ---: | ---: | ---: |
| 10,000 | 170.3 µs | 174.5 µs | +2.5% |
| 32,768 | 310.8 µs | 242.0 µs | -22.1% |
| 100,000 | 318.5 µs | 242.9 µs | -23.7% |
| 1,000,000 | 309.4 µs | 244.9 µs | -20.8% |
| 4,000,000 | 312.4 µs | 240.1 µs | -23.1% |
The 10,000-value control does not enter the dictionary-gather path and averaged 2.5% slower in these measurements. Individual runs varied by several percent.
The additional dictionary sizes were used through a separate local benchmark patch; they are not included in this implementation diff.
Are there any significant user-facing changes?
No public API or intended result changes.
AI assistance: AI tools assisted with implementation, tests, independent review, and validation. I reviewed the code, tests, and description before submission.