Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Minor: reuse Rows buffer in GroupValuesRows #10980

Merged
merged 1 commit into from
Jun 18, 2024

Conversation

alamb
Copy link
Contributor

@alamb alamb commented Jun 18, 2024

Which issue does this PR close?

Part of #7000

Rationale for this change

While working with @jayzhan211 on #10976 I noticed a TODO that could avoid some allocations

What changes are included in this PR?

Use the API added in apache/arrow-rs#4479 to reuse the temporary Rows allocation in the Hash grouping

Are these changes tested?

Functionally tested by CI

Performance benchmarks show maybe a slight improvement in performance (but not major)

Details

--------------------
Benchmark clickbench_1.json
--------------------
┏━━━━━━━━━━━━━━┳━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━┓
┃ Query        ┃  main_base ┃ alamb_less_allocation ┃        Change ┃
┡━━━━━━━━━━━━━━╇━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━┩
│ QQuery 0     │     0.86ms │                0.84ms │     no change │
│ QQuery 1     │    92.70ms │               94.15ms │     no change │
│ QQuery 2     │   190.53ms │              196.09ms │     no change │
│ QQuery 3     │   201.00ms │              200.44ms │     no change │
│ QQuery 4     │  2173.58ms │             2226.78ms │     no change │
│ QQuery 5     │  2004.80ms │             1953.20ms │     no change │
│ QQuery 6     │    85.72ms │               79.90ms │ +1.07x faster │
│ QQuery 7     │    96.01ms │               96.83ms │     no change │
│ QQuery 8     │  3291.22ms │             3273.42ms │     no change │
│ QQuery 9     │  2444.68ms │             2434.64ms │     no change │
│ QQuery 10    │   815.80ms │              821.98ms │     no change │
│ QQuery 11    │   907.62ms │              905.48ms │     no change │
│ QQuery 12    │  2107.15ms │             2093.34ms │     no change │
│ QQuery 13    │  4500.31ms │             4538.54ms │     no change │
│ QQuery 14    │  2859.02ms │             2870.15ms │     no change │
│ QQuery 15    │  2428.72ms │             2451.61ms │     no change │
│ QQuery 16    │  5881.12ms │             5806.99ms │     no change │
│ QQuery 17    │  5844.94ms │             5815.43ms │     no change │
│ QQuery 18    │ 11879.07ms │            11810.61ms │     no change │
│ QQuery 19    │   163.56ms │              168.11ms │     no change │
│ QQuery 20    │  2696.77ms │             2682.39ms │     no change │
│ QQuery 21    │  3457.38ms │             3452.12ms │     no change │
│ QQuery 22    │  9344.43ms │             9269.06ms │     no change │
│ QQuery 23    │ 21928.19ms │            21221.30ms │     no change │
│ QQuery 24    │  1375.81ms │             1336.89ms │     no change │
│ QQuery 25    │  1178.67ms │             1153.24ms │     no change │
│ QQuery 26    │  1490.72ms │             1461.23ms │     no change │
│ QQuery 27    │  4056.40ms │             3962.94ms │     no change │
│ QQuery 28    │ 27492.83ms │            27450.70ms │     no change │
│ QQuery 29    │  1073.24ms │             1060.23ms │     no change │
│ QQuery 30    │  2544.87ms │             2511.73ms │     no change │
│ QQuery 31    │  3253.81ms │             3192.78ms │     no change │
│ QQuery 32    │ 16524.21ms │            16493.70ms │     no change │
│ QQuery 33    │  9428.88ms │             9251.73ms │     no change │
│ QQuery 34    │  9383.64ms │             9261.48ms │     no change │
│ QQuery 35    │  4059.25ms │             4133.75ms │     no change │
│ QQuery 36    │   350.34ms │              357.19ms │     no change │
│ QQuery 37    │   231.59ms │              228.12ms │     no change │
│ QQuery 38    │   190.21ms │              191.66ms │     no change │
│ QQuery 39    │  1148.60ms │             1183.20ms │     no change │
│ QQuery 40    │    85.51ms │               91.20ms │  1.07x slower │
│ QQuery 41    │    80.75ms │               81.69ms │     no change │
│ QQuery 42    │    98.06ms │              100.15ms │     no change │
└──────────────┴────────────┴───────────────────────┴───────────────┘
┏━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━┓
┃ Benchmark Summary                    ┃             ┃
┡━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━┩
│ Total Time (main_base)               │ 169442.60ms │
│ Total Time (alamb_less_allocation)   │ 167967.01ms │
│ Average Time (main_base)             │   3940.53ms │
│ Average Time (alamb_less_allocation) │   3906.21ms │
│ Queries Faster                       │           1 │
│ Queries Slower                       │           1 │
│ Queries with No Change               │          41 │
└──────────────────────────────────────┴─────────────┘

--------------------
Benchmark clickbench_extended.json
--------------------
┏━━━━━━━━━━━━━━┳━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━┓
┃ Query        ┃ main_base ┃ alamb_less_allocation ┃        Change ┃
┡━━━━━━━━━━━━━━╇━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━┩
│ QQuery 0     │ 3706.96ms │             3692.16ms │     no change │
│ QQuery 1     │ 1575.43ms │             1458.20ms │ +1.08x faster │
│ QQuery 2     │ 3138.34ms │             3067.49ms │     no change │
└──────────────┴───────────┴───────────────────────┴───────────────┘
┏━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━┓
┃ Benchmark Summary                    ┃           ┃
┡━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━┩
│ Total Time (main_base)               │ 8420.72ms │
│ Total Time (alamb_less_allocation)   │ 8217.85ms │
│ Average Time (main_base)             │ 2806.91ms │
│ Average Time (alamb_less_allocation) │ 2739.28ms │
│ Queries Faster                       │         1 │
│ Queries Slower                       │         0 │
│ Queries with No Change               │         2 │
└──────────────────────────────────────┴───────────┘

Are there any user-facing changes?

@@ -93,8 +101,9 @@ impl GroupValuesRows {
impl GroupValues for GroupValuesRows {
fn intern(&mut self, cols: &[ArrayRef], groups: &mut Vec<usize>) -> Result<()> {
// Convert the group keys into the row format
// Avoid reallocation when https://github.com/apache/arrow-rs/issues/4479 is available
let group_rows = self.row_converter.convert_columns(cols)?;
let group_rows = &mut self.rows_buffer;
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The idea is that this avoids an allocation per batch

@alamb alamb marked this pull request as ready for review June 18, 2024 14:07
@alamb
Copy link
Contributor Author

alamb commented Jun 18, 2024

Thank you for the review @Dandandan

@alamb alamb merged commit 80f4322 into apache:main Jun 18, 2024
24 of 25 checks passed
findepi pushed a commit to findepi/datafusion that referenced this pull request Jul 16, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants