dongjoon-hyun opened a new pull request, #60444:
URL: https://github.com/apache/spark/pull/60444

   ### What changes were proposed in this pull request?
   
   `RowToColumnarEvaluatorFactory`, which `RowToColumnarExec` runs, kept its 
column vectors as a `Seq[WritableColumnVector]` and converted every input row 
with `converters.convert(row, vectors.toArray)`. `toArray` builds a new array 
and copies the vector references into it, so each row allocated a 
`WritableColumnVector[]` of the column count (32 bytes for 3 columns and 96 
bytes for 20 columns with compressed oops), after a `ClassTag` lookup.
   
   This PR keeps the vectors as an `Array[WritableColumnVector]`, built once 
when the vectors are allocated, and passes it to `convert` directly.
   
   ```scala
   -        private lazy val vectors: Seq[WritableColumnVector] = if 
(enableOffHeapColumnVector) {
   -          OffHeapColumnVector.allocateColumns(numRows, 
schema).toImmutableArraySeq
   +        private lazy val vectors: Array[WritableColumnVector] = if 
(enableOffHeapColumnVector) {
   +          OffHeapColumnVector.allocateColumns(numRows, schema).toArray
   ...
   -            converters.convert(row, vectors.toArray)
   +            converters.convert(row, vectors)
   ```
   
   `new ColumnarBatch(vectors.toArray)` still copies the array once per 
partition, as before.
   
   ### Why are the changes needed?
   
   The per-row array is pure overhead. `RowToColumnarExec` runs whenever a 
columnar consumer sits on top of a row producer, e.g., when 
`ArrowCachedBatchSerializer` caches a query that has an exchange, which AQE 
plans with `RowToColumnar` at the end of the final stage. SPARK-61620 added 
`Cache a shuffled query` to `ArrowCacheBenchmark` for that path.
   
   The `ArrowCacheBenchmark` result files will be regenerated in this PR with 
the GitHub Actions `benchmark.yml` workflow on `AMD EPYC 7763`, the same CPU as 
SPARK-61620. Until then, these are local numbers on Apple M3 Max with JDK 
21.0.13.
   
   `Cache 5M rows after a shuffle` of `ArrowCacheBenchmark`, `Best Time(ms)`, 
in two runs of opposite order:
   
   | Case | Run 1 (before first) | Run 2 (after first) |
   |---|---|---|
   | Arrow cache - shuffled input | 1107 -> 867 (-21.7%) | 1098 -> 920 (-16.2%) 
|
   | Default cache - shuffled input (no `RowToColumnarExec`) | 1387 -> 1329 
(-4.2%) | 1325 -> 1362 (+2.8%) |
   
   The evaluator alone, on 10M `UnsafeRow`s of `int`, `long` and `double` 
columns with the default batch size of 10000, `ns/row` as the minimum over 
iterations:
   
   | Columns | Vectors | Before | After | Allocated bytes per row |
   |---|---|---|---|---|
   | 3 | on-heap | 24.40 | 14.24 (-41.6%) | 32 -> 0 |
   | 3 | off-heap | 26.26 | 14.85 (-43.4%) | 32 -> 0 |
   | 20 | on-heap | 102.52 | 99.53 (-2.9%) | 96 -> 0 |
   | 20 | off-heap | 107.24 | 103.44 (-3.5%) | 96 -> 0 |
   
   The per-row conversion of 20 columns dominates there, so the difference for 
wide rows is within the noise of the measurement.
   
   ### Does this PR introduce _any_ user-facing change?
   
   No.
   
   ### How was this patch tested?
   
   Pass the CIs with the existing tests that run `RowToColumnarExec`, e.g., 
`SparkPlanSuite`, `SparkSessionExtensionSuite`, and 
`ArrowCachedBatchSerializerSuite`.
   
   ### Was this patch authored or co-authored using generative AI tooling?
   
   Generated-by: Claude Opus 5.5
   


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


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to