nikolaobradovic-db opened a new pull request, #12558:
URL: https://github.com/apache/arrow-rs/pull/12558
# Which issue does this PR close?
- Part of #12557
# 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 `Vec`s 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.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]