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

Add lexsort benchmark (#2871) #2929

Merged
merged 3 commits into from
Oct 26, 2022
Merged

Conversation

tustvold
Copy link
Contributor

Which issue does this PR close?

Part of #2781

Rationale for this change

Benchmarks good 😄

What changes are included in this PR?

Adds some benchmarks of the row format, and adds a disclaimer to the lexsort kernels

lexsort_to_indices([i32, i32_opt]): 4096
                        time:   [464.01 µs 464.15 µs 464.32 µs]
Found 3 outliers among 100 measurements (3.00%)
  1 (1.00%) high mild
  2 (2.00%) high severe

lexsort_rows([i32, i32_opt]): 4096
                        time:   [429.55 µs 429.66 µs 429.78 µs]
Found 4 outliers among 100 measurements (4.00%)
  2 (2.00%) high mild
  2 (2.00%) high severe

lexsort_to_indices([i32, i32_opt]): 32768
                        time:   [4.5412 ms 4.5443 ms 4.5486 ms]
Found 5 outliers among 100 measurements (5.00%)
  2 (2.00%) high mild
  3 (3.00%) high severe

lexsort_rows([i32, i32_opt]): 32768
                        time:   [4.0447 ms 4.0460 ms 4.0474 ms]
Found 5 outliers among 100 measurements (5.00%)
  3 (3.00%) high mild
  2 (2.00%) high severe

lexsort_to_indices([i32, str_opt(16)]): 4096
                        time:   [465.90 µs 466.07 µs 466.26 µs]
Found 6 outliers among 100 measurements (6.00%)
  4 (4.00%) high mild
  2 (2.00%) high severe

lexsort_rows([i32, str_opt(16)]): 4096
                        time:   [500.10 µs 500.27 µs 500.49 µs]
Found 8 outliers among 100 measurements (8.00%)
  2 (2.00%) high mild
  6 (6.00%) high severe

lexsort_to_indices([i32, str_opt(16)]): 32768
                        time:   [4.5679 ms 4.5693 ms 4.5707 ms]
Found 9 outliers among 100 measurements (9.00%)
  8 (8.00%) high mild
  1 (1.00%) high severe

lexsort_rows([i32, str_opt(16)]): 32768
                        time:   [4.7611 ms 4.7641 ms 4.7671 ms]
Found 1 outliers among 100 measurements (1.00%)
  1 (1.00%) high mild

lexsort_to_indices([i32, str(16)]): 4096
                        time:   [466.06 µs 466.21 µs 466.36 µs]
Found 2 outliers among 100 measurements (2.00%)
  2 (2.00%) high severe

lexsort_rows([i32, str(16)]): 4096
                        time:   [391.45 µs 391.60 µs 391.76 µs]
Found 5 outliers among 100 measurements (5.00%)
  5 (5.00%) high severe

lexsort_to_indices([i32, str(16)]): 32768
                        time:   [4.5577 ms 4.5590 ms 4.5604 ms]
Found 6 outliers among 100 measurements (6.00%)
  1 (1.00%) high mild
  5 (5.00%) high severe

lexsort_rows([i32, str(16)]): 32768
                        time:   [3.9101 ms 3.9132 ms 3.9162 ms]

lexsort_to_indices([str_opt(16), str(16)]): 4096
                        time:   [878.19 µs 878.43 µs 878.72 µs]
Found 9 outliers among 100 measurements (9.00%)
  4 (4.00%) high mild
  5 (5.00%) high severe

lexsort_rows([str_opt(16), str(16)]): 4096
                        time:   [461.13 µs 461.59 µs 462.23 µs]
Found 23 outliers among 100 measurements (23.00%)
  23 (23.00%) high severe

lexsort_to_indices([str_opt(16), str(16)]): 32768
                        time:   [9.0754 ms 9.0786 ms 9.0823 ms]
Found 8 outliers among 100 measurements (8.00%)
  5 (5.00%) high mild
  3 (3.00%) high severe

lexsort_rows([str_opt(16), str(16)]): 32768
                        time:   [4.5031 ms 4.5072 ms 4.5113 ms]

lexsort_to_indices([str_opt(16), str_opt(50), str(16)]): 4096
                        time:   [863.26 µs 863.49 µs 863.74 µs]
Found 6 outliers among 100 measurements (6.00%)
  4 (4.00%) high mild
  2 (2.00%) high severe

lexsort_rows([str_opt(16), str_opt(50), str(16)]): 4096
                        time:   [537.53 µs 537.76 µs 537.99 µs]
Found 4 outliers among 100 measurements (4.00%)
  4 (4.00%) high severe

lexsort_to_indices([str_opt(16), str_opt(50), str(16)]): 32768
                        time:   [9.0009 ms 9.0051 ms 9.0098 ms]
Found 10 outliers among 100 measurements (10.00%)
  6 (6.00%) high mild
  4 (4.00%) high severe

lexsort_rows([str_opt(16), str_opt(50), str(16)]): 32768
                        time:   [5.3922 ms 5.4006 ms 5.4092 ms]

lexsort_to_indices([str_opt(16), str(16), str_opt(16), str_opt(16), str_opt(16)]): 4096
                        time:   [880.31 µs 880.52 µs 880.75 µs]
Found 4 outliers among 100 measurements (4.00%)
  3 (3.00%) high mild
  1 (1.00%) high severe

lexsort_rows([str_opt(16), str(16), str_opt(16), str_opt(16), str_opt(16)]): 4096
                        time:   [686.41 µs 686.66 µs 686.94 µs]
Found 3 outliers among 100 measurements (3.00%)
  1 (1.00%) high mild
  2 (2.00%) high severe

lexsort_to_indices([str_opt(16), str(16), str_opt(16), str_opt(16), str_opt(16)]): 32768
                        time:   [9.1124 ms 9.1163 ms 9.1207 ms]
Found 10 outliers among 100 measurements (10.00%)
  4 (4.00%) high mild
  6 (6.00%) high severe

lexsort_rows([str_opt(16), str(16), str_opt(16), str_opt(16), str_opt(16)]): 32768
                        time:   [6.8218 ms 6.8290 ms 6.8362 ms]

lexsort_to_indices([i32_opt, dict(100,str_opt(50))]): 4096
                        time:   [523.76 µs 523.95 µs 524.16 µs]
Found 8 outliers among 100 measurements (8.00%)
  6 (6.00%) high mild
  2 (2.00%) high severe

lexsort_rows([i32_opt, dict(100,str_opt(50))]): 4096
                        time:   [430.36 µs 430.61 µs 430.90 µs]
Found 7 outliers among 100 measurements (7.00%)
  4 (4.00%) high mild
  3 (3.00%) high severe

lexsort_to_indices([i32_opt, dict(100,str_opt(50))]): 32768
                        time:   [4.8896 ms 4.8922 ms 4.8950 ms]
Found 15 outliers among 100 measurements (15.00%)
  13 (13.00%) high mild
  2 (2.00%) high severe

lexsort_rows([i32_opt, dict(100,str_opt(50))]): 32768
                        time:   [3.7030 ms 3.7046 ms 3.7063 ms]
Found 3 outliers among 100 measurements (3.00%)
  3 (3.00%) high mild

lexsort_to_indices([dict(100,str_opt(50)), dict(100,str_opt(50))]): 4096
                        time:   [153.02 µs 153.07 µs 153.11 µs]
Found 3 outliers among 100 measurements (3.00%)
  1 (1.00%) high mild
  2 (2.00%) high severe

lexsort_rows([dict(100,str_opt(50)), dict(100,str_opt(50))]): 4096
                        time:   [200.52 µs 200.62 µs 200.73 µs]
Found 7 outliers among 100 measurements (7.00%)
  3 (3.00%) high mild
  4 (4.00%) high severe

Benchmarking lexsort_to_indices([dict(100,str_opt(50)), dict(100,str_opt(50))]): 32768: Warming up for 3.0000 s
Warning: Unable to complete 100 samples in 5.0s. You may wish to increase target time to 6.3s, enable flat sampling, or reduce sample count to 60.
lexsort_to_indices([dict(100,str_opt(50)), dict(100,str_opt(50))]): 32768
                        time:   [1.2349 ms 1.2361 ms 1.2373 ms]
Found 3 outliers among 100 measurements (3.00%)
  2 (2.00%) low mild
  1 (1.00%) high severe

Benchmarking lexsort_rows([dict(100,str_opt(50)), dict(100,str_opt(50))]): 32768: Warming up for 3.0000 s
Warning: Unable to complete 100 samples in 5.0s. You may wish to increase target time to 7.4s, enable flat sampling, or reduce sample count to 50.
lexsort_rows([dict(100,str_opt(50)), dict(100,str_opt(50))]): 32768
                        time:   [1.4587 ms 1.4594 ms 1.4601 ms]
Found 2 outliers among 100 measurements (2.00%)
  1 (1.00%) high mild
  1 (1.00%) high severe

Benchmarking lexsort_to_indices([dict(100,str_opt(50)), dict(100,str_opt(50)), dict(100,str_opt(50)), str(16)]): ...: Warming up for 3.0000 s
Warning: Unable to complete 100 samples in 5.0s. You may wish to increase target time to 7.3s, enable flat sampling, or reduce sample count to 50.
lexsort_to_indices([dict(100,str_opt(50)), dict(100,str_opt(50)), dict(100,str_opt(50)), str(16)]): ...
                        time:   [1.4455 ms 1.4461 ms 1.4468 ms]
Found 11 outliers among 100 measurements (11.00%)
  5 (5.00%) high mild
  6 (6.00%) high severe

lexsort_rows([dict(100,str_opt(50)), dict(100,str_opt(50)), dict(100,str_opt(50)), str(16)]): 4096
                        time:   [531.39 µs 531.58 µs 531.77 µs]
Found 6 outliers among 100 measurements (6.00%)
  4 (4.00%) high mild
  2 (2.00%) high severe

lexsort_to_indices([dict(100,str_opt(50)), dict(100,str_opt(50)), dict(100,str_opt(50)), str(16)]): ... #2
                        time:   [15.592 ms 15.598 ms 15.604 ms]
Found 4 outliers among 100 measurements (4.00%)
  3 (3.00%) high mild
  1 (1.00%) high severe

lexsort_rows([dict(100,str_opt(50)), dict(100,str_opt(50)), dict(100,str_opt(50)), str(16)]): 32768
                        time:   [4.7450 ms 4.7488 ms 4.7526 ms]
Found 1 outliers among 100 measurements (1.00%)
  1 (1.00%) high mild

Benchmarking lexsort_to_indices([dict(100,str_opt(50)), dict(100,str_opt(50)), dict(100,str_opt(50)), str_opt(50)...: Warming up for 3.0000 s
Warning: Unable to complete 100 samples in 5.0s. You may wish to increase target time to 7.1s, enable flat sampling, or reduce sample count to 50.
lexsort_to_indices([dict(100,str_opt(50)), dict(100,str_opt(50)), dict(100,str_opt(50)), str_opt(50)...
                        time:   [1.4102 ms 1.4107 ms 1.4113 ms]
Found 12 outliers among 100 measurements (12.00%)
  5 (5.00%) high mild
  7 (7.00%) high severe

lexsort_rows([dict(100,str_opt(50)), dict(100,str_opt(50)), dict(100,str_opt(50)), str_opt(50)]): 40...
                        time:   [546.89 µs 547.06 µs 547.23 µs]
Found 7 outliers among 100 measurements (7.00%)
  6 (6.00%) high mild
  1 (1.00%) high severe

lexsort_to_indices([dict(100,str_opt(50)), dict(100,str_opt(50)), dict(100,str_opt(50)), str_opt(50)... #2
                        time:   [15.753 ms 15.760 ms 15.768 ms]
Found 5 outliers among 100 measurements (5.00%)
  5 (5.00%) high mild

lexsort_rows([dict(100,str_opt(50)), dict(100,str_opt(50)), dict(100,str_opt(50)), str_opt(50)]): 32...
                        time:   [4.9877 ms 4.9912 ms 4.9947 ms]

Benchmarking lexsort_to_indices([dict(100,str_opt(50)), dict(100,str_opt(50)), dict(100,str_opt(50)), str_opt(50)... #3: Warming up for 3.0000 s
Warning: Unable to complete 100 samples in 5.0s. You may wish to increase target time to 7.1s, enable flat sampling, or reduce sample count to 50.
lexsort_to_indices([dict(100,str_opt(50)), dict(100,str_opt(50)), dict(100,str_opt(50)), str_opt(50)... #3
                        time:   [1.4112 ms 1.4118 ms 1.4124 ms]
Found 8 outliers among 100 measurements (8.00%)
  3 (3.00%) high mild
  5 (5.00%) high severe

lexsort_rows([dict(100,str_opt(50)), dict(100,str_opt(50)), dict(100,str_opt(50)), str_opt(50)]): 40... #2
                        time:   [547.35 µs 547.64 µs 547.99 µs]
Found 3 outliers among 100 measurements (3.00%)
  3 (3.00%) high severe

lexsort_to_indices([dict(100,str_opt(50)), dict(100,str_opt(50)), dict(100,str_opt(50)), str_opt(50)... #4
                        time:   [15.796 ms 15.804 ms 15.813 ms]
Found 5 outliers among 100 measurements (5.00%)
  5 (5.00%) high mild

lexsort_rows([dict(100,str_opt(50)), dict(100,str_opt(50)), dict(100,str_opt(50)), str_opt(50)]): 32... #2
                        time:   [5.0166 ms 5.0226 ms 5.0287 ms]

So sorting using the row format is in the same ballpark or significantly faster, with the performance benefit becoming more stark with more columns

Are there any user-facing changes?

No

@github-actions github-actions bot added the arrow Changes to the arrow crate label Oct 26, 2022
let mut converter = RowConverter::new(fields);
let rows = converter.convert_columns(&arrays).unwrap();
let mut sort: Vec<_> = rows.iter().enumerate().collect();
sort.sort_unstable_by(|(_, a), (_, b)| a.cmp(b));
Copy link
Contributor Author

@tustvold tustvold Oct 26, 2022

Choose a reason for hiding this comment

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

I'm still a little bit confused as to why lexsort_to_indices can use sort_unstable whilst claiming to be a stable sort, but perhaps I've missed some subtlety. I just do the same thing here

Copy link
Contributor

Choose a reason for hiding this comment

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

I thought we changed lexsort_to_indices to be unstable in the name of performance. As in it shouldn't be claiming to be stable

Copy link
Contributor

Choose a reason for hiding this comment

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

I am not sure if the lexsort to indices is correctly doing stable sort. However it's possible to use unstable sort for stable sorting as long as you also sort the indexes:

https://rust-lang.github.io/rfcs/1884-unstable-sort.html

Q: Can stable sort be performed using unstable sort?
A: Yes. If we transform [T] into [(T, usize)] by pairing every element with its index, then perform unstable sort, and finally remove indices, the result will be equivalent to stable sort.

.iter()
.map(|i| *i as u32)
.collect::<Vec<u32>>(),
Ok(UInt32Array::from_iter_values(
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Drive by cleanup to avoid an intermediate array

Copy link
Contributor

@alamb alamb left a comment

Choose a reason for hiding this comment

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

Very nice

let mut converter = RowConverter::new(fields);
let rows = converter.convert_columns(&arrays).unwrap();
let mut sort: Vec<_> = rows.iter().enumerate().collect();
sort.sort_unstable_by(|(_, a), (_, b)| a.cmp(b));
Copy link
Contributor

Choose a reason for hiding this comment

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

I thought we changed lexsort_to_indices to be unstable in the name of performance. As in it shouldn't be claiming to be stable

},
);

c.bench_function(&format!("lexsort_rows({:?}): {}", columns, len), |b| {
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
c.bench_function(&format!("lexsort_rows({:?}): {}", columns, len), |b| {
c.bench_function(&format!("RowFormat: lexsort_rows({:?}): {}", columns, len), |b| {

Copy link
Contributor Author

Choose a reason for hiding this comment

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

There is already an issue with the benchmark names being too long, so going to skip this one

Copy link
Contributor

Choose a reason for hiding this comment

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

classic tradeoff between concision and verboseness 😆

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah I wouldn't mind if there was some way to stop criterion truncating benchmark names, but I can't find such an option

arrow/src/row/mod.rs Outdated Show resolved Hide resolved
Co-authored-by: Andrew Lamb <andrew@nerdnetworks.org>
@tustvold tustvold merged commit 1d36bdf into apache:master Oct 26, 2022
@ursabot
Copy link

ursabot commented Oct 26, 2022

Benchmark runs are scheduled for baseline = 51d3568 and contender = 1d36bdf. 1d36bdf is a master commit associated with this PR. Results will be available as each benchmark for each run completes.
Conbench compare runs links:
[Skipped ⚠️ Benchmarking of arrow-rs-commits is not supported on ec2-t3-xlarge-us-east-2] ec2-t3-xlarge-us-east-2
[Skipped ⚠️ Benchmarking of arrow-rs-commits is not supported on test-mac-arm] test-mac-arm
[Skipped ⚠️ Benchmarking of arrow-rs-commits is not supported on ursa-i9-9960x] ursa-i9-9960x
[Skipped ⚠️ Benchmarking of arrow-rs-commits is not supported on ursa-thinkcentre-m75q] ursa-thinkcentre-m75q
Buildkite builds:
Supported benchmarks:
ec2-t3-xlarge-us-east-2: Supported benchmark langs: Python, R. Runs only benchmarks with cloud = True
test-mac-arm: Supported benchmark langs: C++, Python, R
ursa-i9-9960x: Supported benchmark langs: Python, R, JavaScript
ursa-thinkcentre-m75q: Supported benchmark langs: C++, Java

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
arrow Changes to the arrow crate
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants