perf: optimize native shuffle struct field processing with field-major order#3224
Closed
andygrove wants to merge 3 commits intoapache:mainfrom
Closed
perf: optimize native shuffle struct field processing with field-major order#3224andygrove wants to merge 3 commits intoapache:mainfrom
andygrove wants to merge 3 commits intoapache:mainfrom
Conversation
Optimize struct field processing in native shuffle by using field-major instead of row-major order. This moves type dispatch from O(rows × fields) to O(fields), eliminating per-row type matching overhead. Previously, for each row we iterated over all fields and called `append_field()` which did a type match for EVERY field in EVERY row. For a struct with N fields and M rows, that's N×M type matches. The new approach: 1. First pass: Loop over rows, build struct validity 2. Second pass: For each field, get typed builder once, then process all rows for that field This keeps type dispatch at O(fields) instead of O(rows × fields). For complex nested types (struct, list, map), falls back to existing `append_field` since they have their own recursive processing logic. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Member
Author
|
@sqlbenchmark run tpch |
Add a Criterion benchmark to measure the performance of struct column processing in native shuffle. Tests various struct sizes (5, 10, 20 fields) and row counts (1K, 10K rows). Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #3224 +/- ##
============================================
+ Coverage 56.12% 60.02% +3.89%
- Complexity 976 1429 +453
============================================
Files 119 170 +51
Lines 11743 15746 +4003
Branches 2251 2602 +351
============================================
+ Hits 6591 9451 +2860
- Misses 4012 4976 +964
- Partials 1140 1319 +179 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
Comet TPC-H Benchmark ResultsCommit: Query Times
Total Time: 307.94 seconds Spark Configuration
Automated benchmark run by dfbench |
Comet TPC-H Benchmark ResultsCommit: Query Times
Total Time: 321.87 seconds Spark Configuration
Automated benchmark run by dfbench |
Member
Author
|
replaced with #3289 so that I can work on all related optimizations in a single PR for now |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Optimizes struct field processing in native shuffle by using field-major instead of row-major order. This moves type dispatch from O(rows × fields) to O(fields), eliminating per-row type matching overhead.
The problem:
Previously, for each row we iterated over all fields and called
append_field()which did a type match for EVERY field in EVERY row. For a struct with N fields and M rows, that's N×M type matches where the types never change.The solution:
Field-major processing with two passes:
This reduces type dispatch from O(rows × fields) to O(fields).
For complex nested types (struct, list, map), falls back to existing
append_fieldsince they have their own recursive processing logic.Benchmark Results
Benchmark for converting Spark UnsafeRow with struct columns to Arrow arrays:
The optimization shows 1.2x-1.6x speedup, with larger benefits for:
Test plan
native/core/benches/struct_conversion.rs)🤖 Generated with Claude Code