nikolaobradovic-db opened a new issue, #12557:
URL: https://github.com/apache/arrow-rs/issues/12557

   **Describe the bug**
   
   `ArrowWriter::write` builds a `LevelInfoBuilder` tree for each column of 
each batch
   (`parquet/src/arrow/arrow_writer/levels.rs`). Two parts of this work grow 
faster than the number
   of nodes:
   
   1. `LevelInfoBuilder::finish`: 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.
   2. `LevelInfoBuilder::build` compares the full field subtree with the type 
of the array at every
      node. Each child goes back through `try_new`, so the type check costs 
O(nodes × depth).
   
   Wide and deep schemas that are written in small batches pay this cost on 
every `write`.
   
   **To Reproduce**
   
   Write a struct column with many deep leaves in small batches. For example, 
use a binary tree of
   10 struct levels (1024 leaves) in batches of 16 rows. The existing 
`arrow_writer` bench cases have
   few nodes and large batches, so they do not show the cost.
   
   **Expected behavior**
   
   `finish` collects the leaf levels in O(nodes) work, without a `Vec` for each 
struct node, and
   `build` does not compare the same subtree again at every nesting level.
   
   **Additional context**
   
   On a new bench case of this shape, collecting all leaves into one `Vec` 
makes the write about 12%
   faster in batches of 16 rows. A patch is ready (see the linked PR).
   
   A second change compares the full subtree only once at the root of each 
column. In one comparison
   run on the same case, the first change gave -11.0%, and both changes 
together gave -15.6%. But it
   changes when a mismatch is found for arrays built with `unsafe` code whose 
declared types
   contradict their child arrays. The draft PR #11273 (native REE support), 
whose "Stack C" would
   also remove this walk for ordinary trees, is related. @HippoBaro @alamb, do 
you want that second
   change as a separate PR, or do you prefer to keep it for #11273?
   
   Also related to the wide-schema epic #9722.
   


-- 
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]

  • [I] Parquet: building the leaf ... nikolaobradovic-db (via GitHub) via github

Reply via email to