Repository navigation
perf(parquet): collect leaf levels into one Vec in LevelInfoBuilder::finish - #12558
nikolaobradovic-db wants to merge 2 commits into
Conversation
|
run benchmark arrow_writer |
|
🤖 Benchmark starting (GKE) | trigger Target: arrow_writer Sharding factor: 1 (1 workers). Comparing perf-levels-finish-into (ce73c1d) to 7aa9312 (merge-base) diff Run configurationrun benchmark arrow_writer
shards: 1
Trigger commentResults will be posted when all workers finish. File an issue against this benchmark runner |
alamb
left a comment
There was a problem hiding this comment.
Thank you @nikolaobradovic-db -- this looks good to me
cc @HippoBaro
| /// Each write computes the levels of every column again, so this measures the per-batch | ||
| /// cost of building the levels, which grows with the number of nested nodes. The other | ||
| /// cases have few nodes and large batches, so they do not show this cost. | ||
| fn bench_wide_nested_small_batches(c: &mut Criterion) { |
There was a problem hiding this comment.
Can you please pull these benchmarks into their own PR so we can run them using our bot runner?
There was a problem hiding this comment.
Thanks! I moved the benchmarks into #12561. Once it's merged, I'll rebase this PR on top of it.
|
🤖 Benchmark failed or incomplete (GKE) | trigger Target: arrow_writer Comparing perf-levels-finish-into (ce73c1d) to 7aa9312 (merge-base) diff Run configurationrun benchmark arrow_writer
shards: 1
Trigger commentErrors / missing shardsPer-runner informationarrow_writer — shard 1/1Node: gk3-benchmark-cluster-nap-3rsw35l6-06e2ea5c-8qw4 Instance: c4a-highmem-16 (12 vCPU / 65 GiB) uname: BENCH_COMMAND: cargo bench --features=arrow,async,test_common,experimental,object_store --bench arrow_writerCPU Details (lscpu)Resource UsageNo completed measurement resource samples. File an issue against this benchmark runner |
Which issue does this PR close?
Rationale for this change
ArrowWriter::writecallsLevelInfoBuilder::finishfor each column of each batch. On main,each leaf returns its own
Vec, and each struct node collects a newVecfrom theVecs of itschildren. Thus, each
ArrayLevelsmoves at least once for each enclosing struct. For a binarytree of 10 struct levels with 1024 leaves, this is more than 2,000 allocations for each batch. With
this PR, it is about 10 (one
Vecthat grows).Wide and deep schemas that are written in small batches pay this cost on every
write.What changes are included in this PR?
finishcreates oneVecand calls the new privatefinish_into.finish_intopushes eachleaf into this
Vecin the same depth-first order as before.arrow_writerbench cases:wide_nested_struct_small_batches: 64 Int32 leaves under 2 levels of structs, in batches of64 rows.
wide_deep_nested_struct: a binary tree of 10 struct levels with 1024 leaves (Int64, Utf8,Boolean and Int32 in turn), 2048 rows in batches of 16 and of 128 rows.
The output does not change. The cost of
finishdepends only on the shape of the schema, not onthe data.
Are these changes tested?
The leaf order is covered by the existing tests. If
finish_intoreverses the order of thestruct children, 9 existing tests fail, for example
mixed_struct_list,test_map_arrayandtest_list_mask_struct. All existing tests pass.Speed:
cargo bench -p parquet --bench arrow_writer -- '^(wide_.*|(struct|list|map)[a-z0-9_]*/default|primitive/default)$'.For the benchmark runner, use the first commit,
85fabc1e9(the bench cases only), asbaseline.ref.One idle x86_64 Linux host, 5 alternating rounds of the first commit and this PR. The table shows
the median change of the 5 rounds, and the range of the rounds.
wide_deep_nested_struct/16_rowswide_deep_nested_struct/128_rowswide_nested_struct_small_batches/defaultstruct,list,mapandprimitivecasesThe gain is in the deep tree with small batches. The shallow case is a control and does not
change.
Are there any significant user-facing changes?
No.
AI usage disclosure
An AI coding assistant helped to write the change, the bench cases and this description. I
reviewed all of it and ran it.