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

expression: separated arithmeticPlusIntSig #22026

Open
wants to merge 6 commits into
base: master
Choose a base branch
from

Conversation

Tjianke
Copy link
Contributor

@Tjianke Tjianke commented Dec 25, 2020

What problem does this PR solve?

Issue Number: closes #13973

Problem Summary:

  • Separating ArithmeticPlusIntSig at planning stage will be more efficient then current status

What is changed and how it works?

What's Changed:

  • Impl vectorized, separated func sig from original PlusIntSig, separated PlusIntSig into four signatures by sign/unsign of arguments

How it Works:

Benchmark Result:

 benchstat ~/plusOld.txt plusSSNew.txt 
name                                                                             old time/op    new time/op    delta
VectorizedBuiltinArithmeticFunc/builtinArithmeticPlusIntSig-VecBuiltinFunc-8       5.02µs ± 4%    4.67µs ± 2%   -6.94%  (p=0.000 n=19+19)
VectorizedBuiltinArithmeticFunc/builtinArithmeticPlusIntSig-NonVecBuiltinFunc-8    45.0µs ±83%    30.3µs ± 1%  -32.71%  (p=0.000 n=20+20)

name                                                                             old alloc/op   new alloc/op   delta
VectorizedBuiltinArithmeticFunc/builtinArithmeticPlusIntSig-VecBuiltinFunc-8        0.00B          0.00B          ~     (all equal)
VectorizedBuiltinArithmeticFunc/builtinArithmeticPlusIntSig-NonVecBuiltinFunc-8     0.00B          0.00B          ~     (all equal)

name                                                                             old allocs/op  new allocs/op  delta
VectorizedBuiltinArithmeticFunc/builtinArithmeticPlusIntSig-VecBuiltinFunc-8         0.00           0.00          ~     (all equal)
VectorizedBuiltinArithmeticFunc/builtinArithmeticPlusIntSig-NonVecBuiltinFunc-8      0.00           0.00          ~     (all equal)

benchstat ~/plusOld.txt plusSUNew.txt 
name                                                                             old time/op    new time/op    delta
VectorizedBuiltinArithmeticFunc/builtinArithmeticPlusIntSig-VecBuiltinFunc-8       5.02µs ± 4%    2.81µs ± 1%  -43.94%  (p=0.000 n=19+20)
VectorizedBuiltinArithmeticFunc/builtinArithmeticPlusIntSig-NonVecBuiltinFunc-8    45.0µs ±83%    23.3µs ± 2%  -48.15%  (p=0.000 n=20+20)

name                                                                             old alloc/op   new alloc/op   delta
VectorizedBuiltinArithmeticFunc/builtinArithmeticPlusIntSig-VecBuiltinFunc-8        0.00B          0.00B          ~     (all equal)
VectorizedBuiltinArithmeticFunc/builtinArithmeticPlusIntSig-NonVecBuiltinFunc-8     0.00B          0.00B          ~     (all equal)

name                                                                             old allocs/op  new allocs/op  delta
VectorizedBuiltinArithmeticFunc/builtinArithmeticPlusIntSig-VecBuiltinFunc-8         0.00           0.00          ~     (all equal)
VectorizedBuiltinArithmeticFunc/builtinArithmeticPlusIntSig-NonVecBuiltinFunc-8      0.00           0.00          ~     (all equal)

benchstat ~/plusOld.txt plusUSNew.txt 
name                                                                             old time/op    new time/op    delta
VectorizedBuiltinArithmeticFunc/builtinArithmeticPlusIntSig-VecBuiltinFunc-8       5.02µs ± 4%    2.84µs ± 1%  -43.42%  (p=0.000 n=19+20)
VectorizedBuiltinArithmeticFunc/builtinArithmeticPlusIntSig-NonVecBuiltinFunc-8    45.0µs ±83%    23.3µs ± 2%  -48.30%  (p=0.000 n=20+19)

name                                                                             old alloc/op   new alloc/op   delta
VectorizedBuiltinArithmeticFunc/builtinArithmeticPlusIntSig-VecBuiltinFunc-8        0.00B          0.00B          ~     (all equal)
VectorizedBuiltinArithmeticFunc/builtinArithmeticPlusIntSig-NonVecBuiltinFunc-8     0.00B          0.00B          ~     (all equal)

name                                                                             old allocs/op  new allocs/op  delta
VectorizedBuiltinArithmeticFunc/builtinArithmeticPlusIntSig-VecBuiltinFunc-8         0.00           0.00          ~     (all equal)
VectorizedBuiltinArithmeticFunc/builtinArithmeticPlusIntSig-NonVecBuiltinFunc-8      0.00           0.00          ~     (all equal)

benchstat ~/plusOld.txt plusUUNew.txt 
name                                                                             old time/op    new time/op    delta
VectorizedBuiltinArithmeticFunc/builtinArithmeticPlusIntSig-VecBuiltinFunc-8       5.02µs ± 4%    2.34µs ± 1%  -53.42%  (p=0.000 n=19+19)
VectorizedBuiltinArithmeticFunc/builtinArithmeticPlusIntSig-NonVecBuiltinFunc-8    45.0µs ±83%    23.0µs ± 2%  -48.90%  (p=0.000 n=20+19)

name                                                                             old alloc/op   new alloc/op   delta
VectorizedBuiltinArithmeticFunc/builtinArithmeticPlusIntSig-VecBuiltinFunc-8        0.00B          0.00B          ~     (all equal)
VectorizedBuiltinArithmeticFunc/builtinArithmeticPlusIntSig-NonVecBuiltinFunc-8     0.00B          0.00B          ~     (all equal)

name                                                                             old allocs/op  new allocs/op  delta
VectorizedBuiltinArithmeticFunc/builtinArithmeticPlusIntSig-VecBuiltinFunc-8         0.00           0.00          ~     (all equal)
VectorizedBuiltinArithmeticFunc/builtinArithmeticPlusIntSig-NonVecBuiltinFunc-8      0.00           0.00          ~     (all equal)

plusOld.txt
plusSSNew.txt
plusUSNew.txt
plusSUNew.txt
plusUUNew.txt

Check List

Tests

  • Unit test

Release note

  • separated signatures for builtin PlusIngSig

@ti-srebot ti-srebot added the first-time-contributor Indicates that the PR was contributed by an external member and is a first-time contributor. label Dec 25, 2020
@sre-bot
Copy link
Contributor

sre-bot commented Dec 25, 2020

@Tjianke Tjianke marked this pull request as ready for review December 25, 2020 06:01
@Tjianke Tjianke requested a review from a team as a code owner December 25, 2020 06:01
@Tjianke Tjianke requested review from SunRunAway and removed request for a team December 25, 2020 06:01
@breezewish
Copy link
Member

/run-all-tests

@Tjianke
Copy link
Contributor Author

Tjianke commented Dec 30, 2020

@breeswish PTAL

@Tjianke
Copy link
Contributor Author

Tjianke commented Dec 30, 2020

/run-all-tests

breezewish
breezewish previously approved these changes Dec 30, 2020
Copy link
Member

@breezewish breezewish left a comment

Choose a reason for hiding this comment

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

LGTM. Thanks! @qw4990 @XuHuaiyu PTAL, thanks!

@ti-srebot ti-srebot added the status/LGT1 Indicates that a PR has LGTM 1. label Dec 30, 2020
@Tjianke
Copy link
Contributor Author

Tjianke commented Feb 1, 2021

@qw4990 @XuHuaiyu PTAL, thanks!

Copy link
Contributor

@pingyu pingyu left a comment

Choose a reason for hiding this comment

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

@Tjianke
Seems that it should be math.MaxUint64-uint64(rh) here.

return types.ErrOverflow.GenWithStackByArgs("BIGINT UNSIGNED", fmt.Sprintf("(%s + %s)", b.args[0].String(), b.args[1].String()))
}
if lh > 0 && uint64(rh) > math.MaxUint64-uint64(lh) {
if rh > 0 && uint64(lh) > math.MaxUint64-uint64(lh) {
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
if rh > 0 && uint64(lh) > math.MaxUint64-uint64(lh) {
if rh > 0 && uint64(lh) > math.MaxUint64-uint64(rh) {

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks for pointing out.

@pingyu
Copy link
Contributor

pingyu commented Feb 6, 2021

I think it would be better to add unit tests for OVERFLOW cases. Rest LGTM.

@pingyu
Copy link
Contributor

pingyu commented Feb 7, 2021

LGTM

@ti-srebot ti-srebot removed the status/LGT1 Indicates that a PR has LGTM 1. label Feb 7, 2021
@ti-srebot ti-srebot added the status/LGT2 Indicates that a PR has LGTM 2. label Feb 7, 2021
@pingyu
Copy link
Contributor

pingyu commented Feb 7, 2021

Great !
@breeswish PTAL~

@ti-chi-bot ti-chi-bot added the size/XL Denotes a PR that changes 500-999 lines, ignoring generated files. label Feb 22, 2021
@Tjianke
Copy link
Contributor Author

Tjianke commented Feb 22, 2021

/run-all-tests

@zz-jason
Copy link
Member

@Tjianke could you post the benchmark result to show the performance improvements?

@Tjianke
Copy link
Contributor Author

Tjianke commented Feb 23, 2021

@Tjianke could you post the benchmark result to show the performance improvements?

Benchmark added, no significant regression or improvement.

Note that the main purpose of #13973 and other builtin function separation is to improve efficiency on TiKV side.

@zz-jason
Copy link
Member

@Tjianke could you post the benchmark result to show the performance improvements?

Benchmark added, no significant regression or improvement.

Note that the main purpose of #13973 and other builtin function separation is to improve efficiency on TiKV side.

If the TiKV coprocessor writes the code in the similar way to TiDB, how could it improve the performance in the TiKV side?

Do you have any benchmark result (for the demo code in TiKV) or any analysis on that?

@SunRunAway SunRunAway removed their request for review March 28, 2021 12:50
@Tjianke
Copy link
Contributor Author

Tjianke commented Apr 1, 2021

@Tjianke could you post the benchmark result to show the performance improvements?

Benchmark added, no significant regression or improvement.
Note that the main purpose of #13973 and other builtin function separation is to improve efficiency on TiKV side.

If the TiKV coprocessor writes the code in the similar way to TiDB, how could it improve the performance in the TiKV side?

Do you have any benchmark result (for the demo code in TiKV) or any analysis on that?

Sorry, I cannot provide you TiKV benchmark since I am not familiar with TiKV. But the logic here is that judging args and separating functions at planning stage(in TiDB) would save TiKV the time of judging args, therefore improve efficiency. Origin idea from @breeswish.

@zz-jason
Copy link
Member

From the performance benchmark, the performance is not improved, but the code complexity is improved, so I prefer not to bring in this change if there is no benefit.

@Tjianke
Copy link
Contributor Author

Tjianke commented Apr 12, 2021

From the performance benchmark, the performance is not improved, but the code complexity is improved, so I prefer not to bring in this change if there is no benefit.

Original benchmark was inaccurate, after func sig separation, benchstat cannot compare directly between old and new function signatures, I had to rename benchmark result in newer version to compare, seems like there is improvement in newer versions(benchmark updated in main post).

I wrote a script for quick reproduction.

@ti-chi-bot
Copy link
Member

@Tjianke: PR needs rebase.

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository.

@ti-chi-bot ti-chi-bot added the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Jun 19, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
component/expression first-time-contributor Indicates that the PR was contributed by an external member and is a first-time contributor. needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. size/XL Denotes a PR that changes 500-999 lines, ignoring generated files. status/LGT2 Indicates that a PR has LGTM 2.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Separate signatures for PlusInt
8 participants