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

Speed up the function min_max_string #1374

Merged
merged 5 commits into from
Mar 3, 2022

Conversation

HaoYang670
Copy link
Contributor

@HaoYang670 HaoYang670 commented Mar 1, 2022

Which issue does this PR close?

Closes #1373 .

Rationale for this change

  1. Improve performance
  2. clean up the code

What changes are included in this PR?

  1. Performance is improved when null_count > 0. See benchmark result.
  2. more functional styles and fewer mutable variables

benchmark

min string 512          time:   [1.3687 us 1.3691 us 1.3696 us]                            
                        change: [-7.7279% -7.5833% -7.4242%] (p = 0.00 < 0.05)
                        Performance has improved.
Found 9 outliers among 100 measurements (9.00%)
  1 (1.00%) high mild
  8 (8.00%) high severe

min nulls string 512    time:   [1.6630 us 1.6647 us 1.6665 us]                                  
                        change: [-33.478% -33.362% -33.244%] (p = 0.00 < 0.05)
                        Performance has improved.
Found 3 outliers among 100 measurements (3.00%)
  2 (2.00%) high mild
  1 (1.00%) high severe

Are there any user-facing changes?

No

Signed-off-by: remzi <13716567376yh@gmail.com>
Signed-off-by: remzi <13716567376yh@gmail.com>
@github-actions github-actions bot added the arrow Changes to the arrow crate label Mar 1, 2022
@HaoYang670
Copy link
Contributor Author

Benchmark

Before

min string 512          time:   [1.4824 us 1.4914 us 1.5094 us]                            
                        change: [-2.4834% -0.7235% +0.5457%] (p = 0.44 > 0.05)
                        No change in performance detected.
Found 13 outliers among 100 measurements (13.00%)
  2 (2.00%) high mild
  11 (11.00%) high severe

min nulls string 512    time:   [2.4456 us 2.4528 us 2.4610 us]                                  
                        change: [-0.7299% -0.2597% +0.2043%] (p = 0.26 > 0.05)
                        No change in performance detected.
Found 9 outliers among 100 measurements (9.00%)
  7 (7.00%) high mild
  2 (2.00%) high severe

After

min string 512          time:   [1.5539 us 1.5552 us 1.5565 us]                            
                        change: [-0.4238% -0.2174% -0.0106%] (p = 0.04 < 0.05)
                        Change within noise threshold.
Found 5 outliers among 100 measurements (5.00%)
  1 (1.00%) high mild
  4 (4.00%) high severe

min nulls string 512    time:   [1.8519 us 1.8536 us 1.8552 us]                                  
                        change: [-1.0138% -0.7613% -0.4859%] (p = 0.00 < 0.05)
                        Change within noise threshold.
Found 3 outliers among 100 measurements (3.00%)
  1 (1.00%) low mild
  1 (1.00%) high mild
  1 (1.00%) high severe

@codecov-commenter
Copy link

codecov-commenter commented Mar 1, 2022

Codecov Report

Merging #1374 (4479383) into master (6ee51bc) will increase coverage by 0.04%.
The diff coverage is 62.50%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #1374      +/-   ##
==========================================
+ Coverage   82.99%   83.03%   +0.04%     
==========================================
  Files         181      181              
  Lines       52933    53003      +70     
==========================================
+ Hits        43932    44013      +81     
+ Misses       9001     8990      -11     
Impacted Files Coverage Δ
arrow/src/compute/kernels/aggregate.rs 73.22% <62.50%> (-0.11%) ⬇️
arrow/src/compute/kernels/temporal.rs 97.22% <0.00%> (-0.13%) ⬇️
arrow/src/array/transform/mod.rs 84.52% <0.00%> (ø)
arrow/src/compute/kernels/comparison.rs 92.45% <0.00%> (+0.29%) ⬆️
parquet/src/file/metadata.rs 94.42% <0.00%> (+0.54%) ⬆️
arrow/src/record_batch.rs 94.00% <0.00%> (+2.02%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 6ee51bc...4479383. Read the comment docs.

@HaoYang670
Copy link
Contributor Author

I have tested that if we replace array.value by array.value_unchecked, there will be 10% extra performance improvement on the benchmark min string 512. But it also introduces an unsafe block.

Signed-off-by: remzi <13716567376yh@gmail.com>
n = item;
}
}
array
Copy link
Contributor

Choose a reason for hiding this comment

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

According to your benchmark result, this new way a bit slower than before for nulls?

Copy link
Contributor Author

@HaoYang670 HaoYang670 Mar 1, 2022

Choose a reason for hiding this comment

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

No. You can see the benchmark "min nulls string 512". Time decreases from 2.4us to 1.8us. I this this is performance improvement.

Copy link
Contributor Author

@HaoYang670 HaoYang670 Mar 1, 2022

Choose a reason for hiding this comment

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

Also for the benchmark "min string 512 ", there is no big performance penalty introduced. (time from 1.49us to 1.55us)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Copy link
Contributor

Choose a reason for hiding this comment

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

I think we could speed it up a bit more if we could iterate fast on the non-null 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.

Ok, let me try the array.value_unchecked()

10% extra speed up

Signed-off-by: remzi <13716567376yh@gmail.com>
@HaoYang670
Copy link
Contributor Author

HaoYang670 commented Mar 3, 2022

min string 512          time:   [1.3687 us 1.3691 us 1.3696 us]                            
                        change: [-7.7279% -7.5833% -7.4242%] (p = 0.00 < 0.05)
                        Performance has improved.
Found 9 outliers among 100 measurements (9.00%)
  1 (1.00%) high mild
  8 (8.00%) high severe

min nulls string 512    time:   [1.6630 us 1.6647 us 1.6665 us]                                  
                        change: [-33.478% -33.362% -33.244%] (p = 0.00 < 0.05)
                        Performance has improved.
Found 3 outliers among 100 measurements (3.00%)
  2 (2.00%) high mild
  1 (1.00%) high severe

Using value_unchecked can get 8% extra speedup for not-null values

Signed-off-by: remzi <13716567376yh@gmail.com>
@alamb alamb changed the title Speed up the function min_max_string Improve performance of min and max aggregation kernls (optimize min_max_string) Mar 3, 2022
@alamb alamb changed the title Improve performance of min and max aggregation kernls (optimize min_max_string) Improve performance of min and max aggregation kernels without nulls Mar 3, 2022
@alamb alamb changed the title Improve performance of min and max aggregation kernels without nulls Speed up the function min_max_string Mar 3, 2022
@alamb alamb merged commit c947027 into apache:master Mar 3, 2022
@alamb
Copy link
Contributor

alamb commented Mar 3, 2022

Thanks @HaoYang670 and @Dandandan

@HaoYang670 HaoYang670 deleted the refactor_min_max_string branch March 4, 2022 00:55
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.

Improve performance of min and max aggregation kernels without nulls
4 participants