Skip to content

perf(parquet): collect leaf levels into one Vec in LevelInfoBuilder::finish - #12558

Open
nikolaobradovic-db wants to merge 2 commits into
apache:mainfrom
nikolaobradovic-db:perf-levels-finish-into
Open

nikolaobradovic-db wants to merge 2 commits into
apache:mainfrom
nikolaobradovic-db:perf-levels-finish-into

Conversation

@nikolaobradovic-db

Copy link
Copy Markdown

Which issue does this PR close?

Rationale for this change

ArrowWriter::write calls LevelInfoBuilder::finish for each column of each batch. On main,
each leaf returns its own Vec, and each struct node collects a new Vec from the Vecs of its
children. Thus, each ArrayLevels moves at least once for each enclosing struct. For a binary
tree 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 Vec that grows).

Wide and deep schemas that are written in small batches pay this cost on every write.

What changes are included in this PR?

  • finish creates one Vec and calls the new private finish_into. finish_into pushes each
    leaf into this Vec in the same depth-first order as before.
  • The first commit adds two arrow_writer bench cases:
    • wide_nested_struct_small_batches: 64 Int32 leaves under 2 levels of structs, in batches of
      64 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 finish depends only on the shape of the schema, not on
the data.

Are these changes tested?

The leaf order is covered by the existing tests. If finish_into reverses the order of the
struct children, 9 existing tests fail, for example mixed_struct_list, test_map_array and
test_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), as baseline.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.

Case Change Range
wide_deep_nested_struct/16_rows -12.4% -16.0% .. -7.2%
wide_deep_nested_struct/128_rows -0.4% -11.2% .. +0.1%
wide_nested_struct_small_batches/default -1.5% -2.4% .. +4.8%
23 other struct, list, map and primitive cases -1.4% .. +4.8%

The 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.

@boring-cyborg boring-cyborg Bot added the parquet parquet crate label Dec 4, 2026
@alamb

alamb commented Dec 4, 2026

Copy link
Copy Markdown
Contributor

run benchmark arrow_writer

@adriangbot

Copy link
Copy Markdown

🤖 Benchmark starting (GKE) | trigger

Target: arrow_writer

Sharding factor: 1 (1 workers).

Comparing perf-levels-finish-into (ce73c1d) to 7aa9312 (merge-base) diff

Run configuration
run benchmark arrow_writer
shards: 1
Trigger comment
run benchmark arrow_writer

Results will be posted when all workers finish.


File an issue against this benchmark runner

@alamb alamb left a comment

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.

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

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.

Can you please pull these benchmarks into their own PR so we can run them using our bot runner?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Thanks! I moved the benchmarks into #12561. Once it's merged, I'll rebase this PR on top of it.

@adriangbot

Copy link
Copy Markdown

🤖 Benchmark failed or incomplete (GKE) | trigger

Target: arrow_writer

Comparing perf-levels-finish-into (ce73c1d) to 7aa9312 (merge-base) diff

Run configuration
run benchmark arrow_writer
shards: 1
Trigger comment
run benchmark arrow_writer
Errors / missing shards
arrow_writer — shard 1/1: Benchmark for [this request](https://github.com/apache/arrow-rs/pull/12558#issuecomment-7422462940) hit the 7200s job deadline before finishing.

Benchmarks requested: `arrow_writer`

<details><summary>Kubernetes message</summary>

```
Job was active longer than specified deadline
```

</details>

---
[File an issue](https://github.com/adriangb/datafusion-benchmarking/issues) against this benchmark runner
Per-runner information
arrow_writer — shard 1/1

Node: gk3-benchmark-cluster-nap-3rsw35l6-06e2ea5c-8qw4

Instance: c4a-highmem-16 (12 vCPU / 65 GiB)

uname:

Linux bench-c7422462940-6229-wlm8l 6.12.105+ #1 SMP Sat Sep 19 07:55:25 UTC 2026 aarch64 GNU/Linux

BENCH_COMMAND:

cargo bench --features=arrow,async,test_common,experimental,object_store --bench arrow_writer
CPU Details (lscpu)
Architecture:                            aarch64
CPU op-mode(s):                          64-bit
Byte Order:                              Little Endian
CPU(s):                                  16
On-line CPU(s) list:                     0-15
Vendor ID:                               ARM
Model name:                              Neoverse-V2
Model:                                   1
Thread(s) per core:                      1
Core(s) per cluster:                     16
Socket(s):                               -
Cluster(s):                              1
Stepping:                                r0p1
BogoMIPS:                                2000.00
Flags:                                   fp asimd evtstrm aes pmull sha1 sha2 crc32 atomics fphp asimdhp cpuid asimdrdm jscvt fcma lrcpc dcpop sha3 sm3 sm4 asimddp sha512 sve asimdfhm dit uscat ilrcpc flagm sb paca pacg dcpodp sve2 sveaes svepmull svebitperm svesha3 svesm4 flagm2 frint svei8mm svebf16 i8mm bf16 dgh rng bti
L1d cache:                               1 MiB (16 instances)
L1i cache:                               1 MiB (16 instances)
L2 cache:                                32 MiB (16 instances)
L3 cache:                                80 MiB (1 instance)
NUMA node(s):                            1
NUMA node0 CPU(s):                       0-15
Vulnerability Gather data sampling:      Not affected
Vulnerability Indirect target selection: Not affected
Vulnerability Itlb multihit:             Not affected
Vulnerability L1tf:                      Not affected
Vulnerability Mds:                       Not affected
Vulnerability Meltdown:                  Not affected
Vulnerability Mmio stale data:           Not affected
Vulnerability Reg file data sampling:    Not affected
Vulnerability Retbleed:                  Not affected
Vulnerability Spec rstack overflow:      Not affected
Vulnerability Spec store bypass:         Mitigation; Speculative Store Bypass disabled via prctl
Vulnerability Spectre v1:                Mitigation; __user pointer sanitization
Vulnerability Spectre v2:                Mitigation; CSV2, BHB
Vulnerability Srbds:                     Not affected
Vulnerability Tsa:                       Not affected
Vulnerability Tsx async abort:           Not affected
Vulnerability Vmscape:                   Not affected
Resource Usage

No completed measurement resource samples.


File an issue against this benchmark runner

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

parquet parquet crate

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants