VaibhaveS opened a new pull request, #12392:
URL: https://github.com/apache/arrow-rs/pull/12392

   # Which issue does this PR close?
   
   <!--
   It is not necessary to raise an issue, but it is encouraged if it is a 
non-trivial
   enhancement/bug.
   
   If this PR relates to an existing issue, but does not fully resolve it, 
please change
   the wording below from "Closes #NNN" to "Relates to #NNN" or "Part of #NNN" 
to avoid
   false closing an issue.
   -->
   
   - None. A reviewer asked for this to be split out of #12350, since it also 
changes `ArrowWriter::write`. Relates to #12187.
   
   # Rationale for this change
   
   <!--
   Why are you proposing this change? If this is already explained clearly in 
the
   issue then this section is not needed. Explaining clearly why changes are 
proposed
   helps reviewers understand your changes and offer better suggestions for 
fixes.
   
   Please try to explain the problem you are trying to solve in terms of the 
user-visible
   behavior, rather than the implementation.
   -->
   
   `ArrowWriter` converts some Arrow types to the type it stores, such as 
`Int8`, `UInt16`, and decimals stored as `INT32` or `INT64`. For these, 
`WritePrimitive::map` converts every slot of the array, null slots included, 
and the encoder then gathers the non-null values by index. Converting only the 
values that are written skips the null slots, and lets the encoder write the 
values in order.
   
   This also matters for `ArrowWriter::write_with_selection` in #12350, which 
writes the selected rows of a batch from its original arrays. Without this 
change, it converts the values of every row of the batch, including the rows 
that it skips.
   
   # What changes are included in this PR?
   
   <!--
   There is no need to duplicate the description in the issue here but it is
   sometimes worth providing a summary of the individual changes in this PR.
   -->
   
   - `WritePrimitive::map` converts the values at 
`ArrayLevels::non_null_indices` and passes them to the column writer without 
indices.
   - New `arrow_writer` benchmarks: `converted_primitive`, 
`converted_primitive_non_null` and `converted_primitive_sparse_99pct_null`. 
They write `Int8`, `Int16`, `UInt8`, `UInt16`, `Decimal128(9, 2)` and 
`Decimal128(18, 2)` columns with 25%, 0% and 99% nulls. They are in the first 
commit, a635a056f8dd6be5e316591b711162e53a84d001, so that it can serve as the 
baseline.
   
   # Are these changes tested?
   
   <!--
   We typically require tests for all PRs in order to:
   1. Prevent the code from being accidentally broken by subsequent changes
   2. Serve as another way to document the expected behavior of the code
   
   If tests are not included in your PR, please explain why (for example, are 
they
   covered by existing tests, if so identify these tests)?
   
   If this PR claims a performance improvement, please include evidence such as
   benchmark results.
   
   DO NOT simply paste a list of commands ran to verify the code; this is what 
our
   CI is for and it pollutes the PR. ONLY explain if testing was included with 
this
   PR, or why it wasn't.
   -->
   
   The written files don't change, so the existing round trip tests cover this, 
such as `i8_single_column`, `u8_single_column` and `u16_single_column` in 
`parquet/tests/arrow_writer/roundtrip.rs`. I also checked that the files 
written for these types and `Date64` are byte for byte the same before and 
after this change. The check covered 0%, 25% and 99% nulls, both writer 
versions, bloom filters, page statistics, coerced types and a sliced batch.
   
   Benchmarks: `cargo bench -p parquet --bench arrow_writer -- 
'^converted_primitive[a-z0-9_]*/default$'`. I ran the bench binary of each 
version six times, alternating between them, pinned to one core at high 
priority on a shared 8-core VM. The times are the minimum and median of the six 
Criterion estimates:
   
   | Benchmark | Before (min / median) | After (min / median) | Change (min / 
median) |
   |---|---:|---:|---:|
   | `converted_primitive` (25% nulls) | 126.8 / 156.6 ms | 113.8 / 134.0 ms | 
-10% / -14% |
   | `converted_primitive_non_null` | 86.2 / 105.1 ms | 82.5 / 97.9 ms | -4% / 
-7% |
   | `converted_primitive_sparse_99pct_null` | 14.1 / 15.9 ms | 11.3 / 14.7 ms 
| -20% / -8% |
   
   The VM is noisy: within a single pair of runs, the ratio between the 
versions ranged from 0.72 to 1.22, so the benchmark runner's numbers would be 
more reliable.
   
   With nulls, the gain comes from not converting the values of null slots. 
Without nulls, the gather by index only moves from the encoder into the 
conversion. That input could get slower, since a conversion over a contiguous 
slice can be vectorized, but these runs don't show a slowdown.
   
   # Are there any significant user-facing changes?
   
   <!--
   Significant user-facing changes include:
   - Breaking public API change
   - Significant change to existing functionality (e.g. function returns 
something different)
   
   These need to be explicitly called out to ensure we have proper 
documentation if
   required and to ensure we follow proper semantic versioning.
   
   DO NOT restate the changes of this PR; if a bug was fixed and already 
explained
   above, we don't need this to be restated as a user-facing change.
   -->
   
   No.
   
   # AI usage disclosure
   
   <!--
   If you used AI tools, briefly describe what they helped generate.
   See 
https://github.com/apache/arrow-rs/blob/main/CONTRIBUTING.md#ai-generated-submissions.
   Delete this section if you did not use AI tools.
   -->
   
   GitHub Copilot (agent mode) wrote the change, the benchmarks and this 
description at my direction, and ran the measurements.


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

Reply via email to