perf(arrow-array): build null, map, and dictionary arrays directly in builder finish (#11717) #12353
All Vouch review confidence checks passed
Residual risk 0.21 = Change Risk (0.48) × (1 − Review Confidence (0.57)).
Review depth and reviewer attention state are adequate.
Model 1 · Change Risk (XGBoost)
Score: 0.48 · 523 lines diff across 6 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.375
Shallow Review Depth
shallow_review_depth
0.289
Real PR Conversation Timeline
1 comments
"Review active on #12353"
general
weight: 0.35
Mola-maker
Which issue does this PR close?
Rationale for this change
#12228 moved the primitive, boolean, byte and fixed-size-binary builders off
ArrayData, leaving the remaining builders on the old path:Every
finishin these builders still pays for aVec<Buffer>, theArrayDataconstruction, buffer-count checks, and theVecteardown. The overhead is a fixed cost per array, so it dominates when callers finish many small arrays.NullBuilderwas the most extreme case: building aNullArrayof any length does not need any buffer at all, yet it went throughArrayData.This also removes the last
unsafeblock that existed only to satisfyArrayData's invariants rather than an invariant of the typed array itself.What changes are included in this PR?
NullBuilder::finish/finish_clonednow constructNullArray::new(len)directly.MapBuilder::finish_helpernow buildsOffsetBufferand callsMapArray::new_uncheckedinstead of assemblingArrayData. The now-derivablelenparameter was removed fromfinish_helperand its three callers.PrimitiveDictionaryBuilder,GenericByteDictionaryBuilder,FixedSizeBinaryDictionaryBuilder) now callDictionaryArray::new_unchecked(keys, Arc::new(values))infinish,finish_cloned, andfinish_preserve_valuesinstead of building data types and child data throughArrayDataBuilder.The dictionary builders no longer construct the dictionary
DataTypethemselves;new_uncheckedderives it from the keys and values arrays.Imports that became unused (
arrow_data::ArrayData,ArrayDataBuilder, and production-sideDataType) were removed. Tests that still needDataTypeimport it locally.This PR intentionally does not change
UnionBuilder, which needs dynamic dispatch fromDataTypeto a typed constructor.Are these changes tested?
The existing builder suites cover
finish,finish_cloned,finish_preserve_values, builder reuse, null handling, empty maps, and dictionary key overflow. The fullarrow-arraytest suite passes (762 unit tests and 209 doctests), as does theforce_validateconfiguration (750 tests) and thearrowarray transform tests (37 tests). Clippy with--all-features --all-targets -- -D warningsandcargo fmt --all -- --checkboth pass.An earlier revision of this PR included a
builder_finishbenchmark. It was dropped following review feedback on the benchmark PR (#12356): the change reduces work and allocations visibly by inspection, and adding a micro-benchmark per builder risks chasing allocator noise rather than real regressions. The comparison below was measured locally before the benchmark was removed.Local numbers (release, criterion, 1 / 8 / 64 elements, whole build-then-finish loop):
| Bench | Before | After | Change |
|---|---:|---:|---:|
|
null_builder/len:8| 45.1 ns | 342 ps | -99% ||
map_builder/len:1| 1.018 µs | 586 ns | -42% ||
map_builder/len:64| 1.471 µs | 1.048 µs | -29% ||
primitive_dictionary/len:1| 381 ns | 210 ns | -45% ||
primitive_dictionary/len:64| 808 ns | 628 ns | -22% ||
byte_dictionary/len:1| 602 ns | 410 ns | -32% ||
fixed_size_binary_dictionary/len:1| 513 ns | 305 ns | -41% ||
fixed_size_binary_dictionary/len:64| 1.47 µs | 1.03 µs | -30% |These are local measurements and are not required to justify the change; the primary argument is that the code performs strictly less work: one fewer
Vec<Buffer>allocation per finished array, noArrayDataconstruction, no buffer-count validation, and noDataTypereconstruction in the dictionary builders.Are there any significant user-facing changes?
No public API changes. The output arrays keep the same data types, values, nulls, and builder-reset behavior.
MapBuilder::finish_helperis private, so removing itslenparameter is not user-visible.AI usage disclosure
This change and its tests were prepared with AI assistance. I reviewed the implementation and verified the tests, Clippy, and formatting locally.