You are viewing a plain text version of this content. The canonical link for it is here.
Posted to github@datafusion.apache.org by "andygrove (via GitHub)" <gi...@apache.org> on 2026/01/21 02:48:59 UTC

[PR] feat: [EXPERIMENTAL] direct native shuffle execution optimization [datafusion-comet]

andygrove opened a new pull request, #3230:
URL: https://github.com/apache/datafusion-comet/pull/3230

   ## Summary
   
   This PR introduces an **experimental** optimization that allows the native shuffle writer to directly execute the child native plan instead of reading intermediate batches via JNI. This avoids the JNI round-trip for single-source native plans.
   
   **Current flow:**
   ```
   Native Plan → ColumnarBatch → JNI → ScanExec → ShuffleWriterExec
   ```
   
   **Optimized flow:**
   ```
   Native Plan → (directly in native) → ShuffleWriterExec
   ```
   
   ### Configuration
   
   The optimization is controlled by a new config option:
   - `spark.comet.exec.shuffle.directNative.enabled` (default: `false`)
   
   ### Scope
   
   The optimization currently applies when:
   - Native shuffle mode is enabled (`spark.comet.shuffle.mode=native`)
   - The shuffle's child is a single-source native plan with `CometNativeScanExec`
   - The partitioning is not `RangePartitioning` (which requires sampling)
   
   ### Changes
   
   | File | Change |
   |------|--------|
   | `CometShuffleDependency.scala` | Added `childNativePlan` field to pass native plan to writer |
   | `CometShuffleExchangeExec.scala` | Added detection logic for single-source native plans |
   | `CometShuffleManager.scala` | Pass native plan to shuffle writer |
   | `CometNativeShuffleWriter.scala` | Use child native plan directly when available |
   | `CometConf.scala` | Added `COMET_SHUFFLE_DIRECT_NATIVE_ENABLED` config option |
   | `CometDirectNativeShuffleSuite.scala` | Comprehensive test suite with 15 tests |
   
   ## Test plan
   
   - [x] Added `CometDirectNativeShuffleSuite` with 15 tests covering:
     - Basic optimization with single scan source
     - Filter/project operators
     - Single partition and multi-partition cases
     - Config enable/disable behavior
     - Range partitioning fallback
     - JVM shuffle mode fallback
     - Various data types
     - Edge cases (empty tables, filtered results)
     - Correctness comparison between optimized and non-optimized paths
   - [x] Verified existing `CometNativeShuffleSuite` tests still pass (16/16)
   
   🤖 Generated with [Claude Code](https://claude.ai/code)


-- 
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: github-unsubscribe@datafusion.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For additional commands, e-mail: github-help@datafusion.apache.org


Re: [PR] feat: Add direct native shuffle execution optimization [datafusion-comet]

Posted by "andygrove (via GitHub)" <gi...@apache.org>.
andygrove closed pull request #3230: feat: Add direct native shuffle execution optimization
URL: https://github.com/apache/datafusion-comet/pull/3230


-- 
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: github-unsubscribe@datafusion.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For additional commands, e-mail: github-help@datafusion.apache.org


Re: [PR] feat: [EXPERIMENTAL] direct native shuffle execution optimization [datafusion-comet]

Posted by "andygrove (via GitHub)" <gi...@apache.org>.
andygrove commented on PR #3230:
URL: https://github.com/apache/datafusion-comet/pull/3230#issuecomment-3853734926

   @viirya I'm curious what you think about this idea. Does it make sense?


-- 
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: github-unsubscribe@datafusion.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For additional commands, e-mail: github-help@datafusion.apache.org


Re: [PR] feat: Add direct native shuffle execution optimization [datafusion-comet]

Posted by "andygrove (via GitHub)" <gi...@apache.org>.
andygrove commented on PR #3230:
URL: https://github.com/apache/datafusion-comet/pull/3230#issuecomment-4422846503

   closing this in favor of https://github.com/apache/datafusion-comet/pull/3930 which should be good enough


-- 
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: github-unsubscribe@datafusion.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For additional commands, e-mail: github-help@datafusion.apache.org


Re: [PR] feat: [EXPERIMENTAL] direct native shuffle execution optimization [datafusion-comet]

Posted by "andygrove (via GitHub)" <gi...@apache.org>.
andygrove commented on PR #3230:
URL: https://github.com/apache/datafusion-comet/pull/3230#issuecomment-3886142297

   > Looks like `CometNativeShuffleWriter` was added after, I am not familiar with its design. I took a quick look at the code. So it is basically a `ShuffleWriter` and executes a native plan to write inputs from an iterator of `ColumnarBatch` into shuffle file. Although it executes a native plan to write, its input is still coming from JVM even its input plan maybe a native plan too.
   > 
   > So this idea is to avoid the JVM/JNI overhead on the input. It sounds good.
   
   Thanks for taking a look! I will keep experimenting with this.


-- 
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: github-unsubscribe@datafusion.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For additional commands, e-mail: github-help@datafusion.apache.org


Re: [PR] feat: [EXPERIMENTAL] direct native shuffle execution optimization [datafusion-comet]

Posted by "andygrove (via GitHub)" <gi...@apache.org>.
andygrove commented on PR #3230:
URL: https://github.com/apache/datafusion-comet/pull/3230#issuecomment-3886140554

   @sqlbenchmark run tpch --iterations 3


-- 
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: github-unsubscribe@datafusion.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For additional commands, e-mail: github-help@datafusion.apache.org


Re: [PR] feat: [EXPERIMENTAL] direct native shuffle execution optimization [datafusion-comet]

Posted by "codecov-commenter (via GitHub)" <gi...@apache.org>.
codecov-commenter commented on PR #3230:
URL: https://github.com/apache/datafusion-comet/pull/3230#issuecomment-3776105145

   ## [Codecov](https://app.codecov.io/gh/apache/datafusion-comet/pull/3230?dropdown=coverage&src=pr&el=h1&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) Report
   :x: Patch coverage is `3.84615%` with `125 lines` in your changes missing coverage. Please review.
   :white_check_mark: Project coverage is 9.84%. Comparing base ([`f09f8af`](https://app.codecov.io/gh/apache/datafusion-comet/commit/f09f8af64c6599255e116a376f4f008f2fd63b43?dropdown=coverage&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache)) to head ([`15c88da`](https://app.codecov.io/gh/apache/datafusion-comet/commit/15c88da4289e9f21ad2f740bee07f1de712df0c2?dropdown=coverage&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache)).
   :warning: Report is 861 commits behind head on main.
   
   | [Files with missing lines](https://app.codecov.io/gh/apache/datafusion-comet/pull/3230?dropdown=coverage&src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) | Patch % | Lines |
   |---|---|---|
   | [...t/execution/shuffle/CometNativeShuffleWriter.scala](https://app.codecov.io/gh/apache/datafusion-comet/pull/3230?src=pr&el=tree&filepath=spark%2Fsrc%2Fmain%2Fscala%2Forg%2Fapache%2Fspark%2Fsql%2Fcomet%2Fexecution%2Fshuffle%2FCometNativeShuffleWriter.scala&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache#diff-c3Bhcmsvc3JjL21haW4vc2NhbGEvb3JnL2FwYWNoZS9zcGFyay9zcWwvY29tZXQvZXhlY3V0aW9uL3NodWZmbGUvQ29tZXROYXRpdmVTaHVmZmxlV3JpdGVyLnNjYWxh) | 0.00% | [86 Missing :warning: ](https://app.codecov.io/gh/apache/datafusion-comet/pull/3230?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) |
   | [...t/execution/shuffle/CometShuffleExchangeExec.scala](https://app.codecov.io/gh/apache/datafusion-comet/pull/3230?src=pr&el=tree&filepath=spark%2Fsrc%2Fmain%2Fscala%2Forg%2Fapache%2Fspark%2Fsql%2Fcomet%2Fexecution%2Fshuffle%2FCometShuffleExchangeExec.scala&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache#diff-c3Bhcmsvc3JjL21haW4vc2NhbGEvb3JnL2FwYWNoZS9zcGFyay9zcWwvY29tZXQvZXhlY3V0aW9uL3NodWZmbGUvQ29tZXRTaHVmZmxlRXhjaGFuZ2VFeGVjLnNjYWxh) | 0.00% | [35 Missing :warning: ](https://app.codecov.io/gh/apache/datafusion-comet/pull/3230?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) |
   | [...met/execution/shuffle/CometShuffleDependency.scala](https://app.codecov.io/gh/apache/datafusion-comet/pull/3230?src=pr&el=tree&filepath=spark%2Fsrc%2Fmain%2Fscala%2Forg%2Fapache%2Fspark%2Fsql%2Fcomet%2Fexecution%2Fshuffle%2FCometShuffleDependency.scala&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache#diff-c3Bhcmsvc3JjL21haW4vc2NhbGEvb3JnL2FwYWNoZS9zcGFyay9zcWwvY29tZXQvZXhlY3V0aW9uL3NodWZmbGUvQ29tZXRTaHVmZmxlRGVwZW5kZW5jeS5zY2FsYQ==) | 0.00% | [2 Missing :warning: ](https://app.codecov.io/gh/apache/datafusion-comet/pull/3230?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) |
   | [.../comet/execution/shuffle/CometShuffleManager.scala](https://app.codecov.io/gh/apache/datafusion-comet/pull/3230?src=pr&el=tree&filepath=spark%2Fsrc%2Fmain%2Fscala%2Forg%2Fapache%2Fspark%2Fsql%2Fcomet%2Fexecution%2Fshuffle%2FCometShuffleManager.scala&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache#diff-c3Bhcmsvc3JjL21haW4vc2NhbGEvb3JnL2FwYWNoZS9zcGFyay9zcWwvY29tZXQvZXhlY3V0aW9uL3NodWZmbGUvQ29tZXRTaHVmZmxlTWFuYWdlci5zY2FsYQ==) | 0.00% | [2 Missing :warning: ](https://app.codecov.io/gh/apache/datafusion-comet/pull/3230?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) |
   
   <details><summary>Additional details and impacted files</summary>
   
   
   
   ```diff
   @@             Coverage Diff              @@
   ##               main   #3230       +/-   ##
   ============================================
   - Coverage     56.12%   9.84%   -46.29%     
   + Complexity      976     234      -742     
   ============================================
     Files           119     170       +51     
     Lines         11743   15799     +4056     
     Branches       2251    2589      +338     
   ============================================
   - Hits           6591    1555     -5036     
   - Misses         4012   14067    +10055     
   + Partials       1140     177      -963     
   ```
   </details>
   
   [:umbrella: View full report in Codecov by Sentry](https://app.codecov.io/gh/apache/datafusion-comet/pull/3230?dropdown=coverage&src=pr&el=continue&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache).   
   :loudspeaker: Have feedback on the report? [Share it here](https://about.codecov.io/codecov-pr-comment-feedback/?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache).
   <details><summary> :rocket: New features to boost your workflow: </summary>
   
   - :snowflake: [Test Analytics](https://docs.codecov.com/docs/test-analytics): Detect flaky tests, report on failures, and find test suite problems.
   </details>


-- 
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: github-unsubscribe@datafusion.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For additional commands, e-mail: github-help@datafusion.apache.org


Re: [PR] feat: Add direct native shuffle execution optimization [experimental] [datafusion-comet]

Posted by "andygrove (via GitHub)" <gi...@apache.org>.
andygrove closed pull request #3230: feat: Add direct native shuffle execution optimization [experimental]
URL: https://github.com/apache/datafusion-comet/pull/3230


-- 
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: github-unsubscribe@datafusion.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For additional commands, e-mail: github-help@datafusion.apache.org


Re: [PR] feat: [EXPERIMENTAL] direct native shuffle execution optimization [datafusion-comet]

Posted by "viirya (via GitHub)" <gi...@apache.org>.
viirya commented on PR #3230:
URL: https://github.com/apache/datafusion-comet/pull/3230#issuecomment-3856516072

   Looks like `CometNativeShuffleWriter` was added after, I am not familiar with its design. I took a quick look at the code. So it is basically a `ShuffleWriter` and executes a native plan to write inputs from an iterator of `ColumnarBatch` into shuffle file. Although it executes a native plan to write, its input is still coming from JVM even its input plan maybe a native plan too.
   
   So this idea is to avoid the JVM/JNI overhead on the input. It sounds good.
   


-- 
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: github-unsubscribe@datafusion.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For additional commands, e-mail: github-help@datafusion.apache.org


Re: [PR] feat: [EXPERIMENTAL] direct native shuffle execution optimization [datafusion-comet]

Posted by "sqlbenchmark (via GitHub)" <gi...@apache.org>.
sqlbenchmark commented on PR #3230:
URL: https://github.com/apache/datafusion-comet/pull/3230#issuecomment-3886365907

   ## Comet TPC-H Benchmark Results
   
   **Baseline:** `main` (`b0477a72`)
   **PR:** `191e5194` - Merge apache/main into direct-native-shuffle-execution
   **Scale Factor:** SF100
   **Iterations:** 3
   
   ### Query Times
   
   | Query | Baseline Avg (s) | Baseline Best (s) | PR Avg (s) | PR Best (s) | Change (Avg) | Change (Best) |
   |-------|-----------------|-------------------|-----------|------------|-------------|--------------|
   | Q1 | 9.92 | 9.38 | 9.78 | 9.19 | :white_circle: -1.5% | :white_circle: -2.1% |
   | Q2 | 5.20 | 4.82 | 5.25 | 4.96 | :white_circle: +0.9% | :white_circle: +2.7% |
   | Q3 | 9.77 | 9.58 | 9.88 | 9.75 | :white_circle: +1.1% | :white_circle: +1.8% |
   | Q4 | 10.95 | 10.78 | 11.10 | 10.86 | :white_circle: +1.4% | :white_circle: +0.7% |
   | Q5 | 18.81 | 18.67 | 18.91 | 18.72 | :white_circle: +0.5% | :white_circle: +0.2% |
   | Q6 | 2.40 | 2.37 | 2.44 | 2.36 | :white_circle: +1.5% | :white_circle: -0.1% |
   | Q7 | 12.22 | 11.92 | 12.37 | 12.09 | :white_circle: +1.2% | :white_circle: +1.4% |
   | Q8 | 24.70 | 24.30 | 24.88 | 24.34 | :white_circle: +0.7% | :white_circle: +0.2% |
   | Q9 | 39.62 | 38.06 | 39.49 | 37.92 | :white_circle: -0.3% | :white_circle: -0.4% |
   | Q10 | 10.62 | 10.51 | 10.58 | 10.27 | :white_circle: -0.3% | :white_circle: -2.3% |
   | Q11 | 4.39 | 4.30 | 4.41 | 4.32 | :white_circle: +0.5% | :white_circle: +0.4% |
   | Q12 | 7.04 | 6.98 | 7.13 | 7.06 | :white_circle: +1.3% | :white_circle: +1.1% |
   | Q13 | 7.21 | 6.81 | 7.29 | 6.90 | :white_circle: +1.0% | :white_circle: +1.5% |
   | Q14 | 3.56 | 3.50 | 3.70 | 3.58 | :white_circle: +4.0% | :white_circle: +2.2% |
   | Q15 | 7.14 | 7.07 | 7.29 | 7.28 | :white_circle: +2.1% | :white_circle: +2.9% |
   | Q16 | 4.28 | 4.17 | 4.42 | 4.12 | :white_circle: +3.2% | :white_circle: -1.1% |
   | Q17 | 32.56 | 32.15 | 32.74 | 32.28 | :white_circle: +0.6% | :white_circle: +0.4% |
   | Q18 | 33.68 | 33.33 | 33.79 | 33.53 | :white_circle: +0.3% | :white_circle: +0.6% |
   | Q19 | 6.94 | 6.72 | 6.80 | 6.55 | :white_circle: -2.0% | :white_circle: -2.5% |
   | Q20 | 6.65 | 6.58 | 6.70 | 6.66 | :white_circle: +0.8% | :white_circle: +1.3% |
   | Q21 | 45.62 | 45.22 | 46.19 | 45.70 | :white_circle: +1.3% | :white_circle: +1.1% |
   | Q22 | 4.90 | 4.85 | 4.98 | 4.94 | :white_circle: +1.6% | :white_circle: +2.0% |
   | **Total** | **308.17** | **302.05** | **310.11** | **303.38** | :white_circle: +0.6% | :white_circle: +0.4% |
   
   <details>
   <summary><b>Spark Configuration</b></summary>
   
   | Setting | Value |
   |---------|-------|
   | Spark Master | `local[*]` |
   | Driver Memory | 32G |
   | Driver Cores | 8 |
   | Executor Memory | 32G |
   | Executor Cores | 8 |
   | Off-Heap Enabled | true |
   | Off-Heap Size | 24g |
   | Shuffle Manager | `CometShuffleManager` |
   | Comet Replace SMJ | true |
   
   </details>
   
   ---
   *Automated benchmark run by dfbench*


-- 
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: github-unsubscribe@datafusion.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For additional commands, e-mail: github-help@datafusion.apache.org