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

   **Is your feature request related to a problem or challenge?**
   
   `DictEncoder` uses `Interner` to find the dictionary key of each value. 
`Interner::new`
   (`parquet/src/util/interner.rs`) creates its dedup table with 
`HashTable::with_capacity(4096)`.
   With hashbrown 0.17, this table has 8192 buckets and uses 73,744 bytes.
   
   The column writer creates its `DictEncoder` when the writer is created. In 
`ArrowWriter`, this
   applies to each dictionary column except BYTE_ARRAY. BYTE_ARRAY columns use 
a different encoder,
   and its table already starts empty.
   
   `ArrowWriter` creates the writers for all columns of a row group at the same 
time. Thus, a wide
   schema allocates many tables before it writes a value. A column that gets no 
value in the row group
   never uses its table. Examples are an all-null column and a sparse field of 
a wide struct.
   
   Example: 1,024 rows of 1,000 nullable Int64 columns, where one column in 100 
has values. With the
   default writer properties, the peak memory is about 74 MiB. The tables of 
the 990 all-null columns
   use about 70 MiB of this.
   
   The 4096 capacity came from #2273 and #2272 (2022). It prevents resizes in 
the dense `primitive`
   writer benches.
   
   **Describe the solution you'd like**
   
   Create the table empty with `HashTable::new()`. Then reserve 4096 keys in 
`DictEncoder::put`,
   before the first value. A column that gets values then starts with the same 
table as today. Thus,
   the dense write path and the benefit of #2273 do not change. A column that 
gets no value does not
   allocate a table.
   
   The output does not change, because dictionary keys follow the first-seen 
order of the values.
   
   #11858 uses the same "allocate on first use" approach for zstd contexts.
   
   **Describe alternatives you've considered**
   
   - Create the table empty and let it grow, with no reserve. This saves the 
same memory. The existing
     `primitive` and `ndv` benches show no difference, because each bench 
writes one large column
     chunk for each column. But columns with values then pay for the resizes up 
to 4096 keys again.
     #2273 removed this cost.
   - Use a small fixed capacity, for example 64 keys (1,168 bytes). Empty 
columns still allocate a
     table, and dense columns still resize from 64 to 4096 keys.
   - Size the table from the first batch. This needs a new `Interner` API. 
Also, the number of values
     in the first batch does not predict the number of distinct values.
   
   **Additional context**
   
   A patch is ready in the linked PR. It adds a bench case for this schema to
   `arrow_writer_peak_memory`.
   


-- 
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: each primitive dic... nikolaobradovic-db (via GitHub) via github

Reply via email to