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

perf(array): optimize performance of literal expression #6877

Merged
merged 9 commits into from
Dec 13, 2022
Merged

Conversation

wangrunji0408
Copy link
Contributor

@wangrunji0408 wangrunji0408 commented Dec 13, 2022

I hereby agree to the terms of the Singularity Data, Inc. Contributor License Agreement.

What's changed and what's your intention?

  • introduce Array::raw_iter to efficiently iterate over raw values regardless of null.
  • introduce ArrayBuilder::append_n to efficiently append the same value multiple times.
  • remove the head from Bitmap

With these optimizations, the evaluation time of literal expressions dropped from 2.2us to 150ns.

This PR also adds an optimized version of i32 + i32 using raw iterator in the bench, reducing time from 3.3us to 350ns.

Checklist

  • I have written necessary rustdoc comments
  • I have added necessary unit tests and integration tests
  • All checks passed in ./risedev check (or alias, ./risedev c)

Refer to a related PR or issue link (optional)

#6868

Signed-off-by: Runji Wang <wangrunji0408@163.com>
Signed-off-by: Runji Wang <wangrunji0408@163.com>
Signed-off-by: Runji Wang <wangrunji0408@163.com>
Signed-off-by: Runji Wang <wangrunji0408@163.com>
Copy link
Member

@BugenZhao BugenZhao left a comment

Choose a reason for hiding this comment

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

🚀

src/common/src/array/iterator.rs Outdated Show resolved Hide resolved
src/common/src/array/bytes_array.rs Outdated Show resolved Hide resolved
src/common/src/array/primitive_array.rs Show resolved Hide resolved
src/common/src/array/bytes_array.rs Show resolved Hide resolved
Copy link
Contributor

@BowenXiao1999 BowenXiao1999 left a comment

Choose a reason for hiding this comment

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

Great Job, LGTM!

  1. How should use the append_n in executor (e.g. build a chunk) or is it only for bench? Usually we do not how many values are the same before.
  2. I saw perf(expr): add initial microbenchmark for expressions #6856 has mentioned some potential improvements. Are all kinds of improvements has been includeded in this pr or there is more?

Signed-off-by: Runji Wang <wangrunji0408@163.com>
@st1page
Copy link
Contributor

st1page commented Dec 13, 2022

3.3us to 350us

350ns?

@wangrunji0408
Copy link
Contributor Author

3.3us to 350us

350ns?

Sure. Thanks for pointing it out. 🥵

@wangrunji0408
Copy link
Contributor Author

How should use the append_n in executor (e.g. build a chunk) or is it only for bench? Usually we do not how many values are the same before.

It is a method in ArrayBuilder trait. There's also a new method append_datum_n in ArrayBuilderImpl. So they should be generally available. But I think the most use case would still be evaluating literal expressions.

I saw #6856 has mentioned some potential improvements. Are all kinds of improvements has been includeded in this pr or there is more?

Yes, that's all.

Signed-off-by: Runji Wang <wangrunji0408@163.com>
@jon-chuang
Copy link
Contributor

Although we demonstrated that we can improve the i32 add performance possibly by vectorizing each of the steps (null check, arithmetic and check overflow), can I ask whether any benchmark demonstrates improvement due to the use of append_n?

I guess the intention is simply to provide an additional method that we can benchmark the usage of in the future?

Signed-off-by: Runji Wang <wangrunji0408@163.com>
@wangrunji0408
Copy link
Contributor Author

Although we demonstrated that we can improve the i32 add performance possibly by vectorizing each of the steps (null check, arithmetic and check overflow), can I ask whether any benchmark demonstrates improvement due to the use of append_n?

Sure. The bench "expr/constant" (literal expression). Previously it could only append the same value one by one. Now it can append them all at once.

@codecov
Copy link

codecov bot commented Dec 13, 2022

Codecov Report

Merging #6877 (6d8c3a2) into main (c188e5f) will decrease coverage by 0.01%.
The diff coverage is 71.08%.

@@            Coverage Diff             @@
##             main    #6877      +/-   ##
==========================================
- Coverage   73.16%   73.15%   -0.02%     
==========================================
  Files        1033     1033              
  Lines      164925   165019      +94     
==========================================
+ Hits       120665   120714      +49     
- Misses      44260    44305      +45     
Flag Coverage Δ
rust 73.15% <71.08%> (-0.02%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

Impacted Files Coverage Δ
src/common/src/array/iterator.rs 79.45% <0.00%> (-18.86%) ⬇️
src/expr/src/expr/expr_binary_nonnull.rs 62.60% <ø> (ø)
src/common/src/array/utf8_array.rs 90.76% <22.22%> (-2.52%) ⬇️
src/common/src/array/struct_array.rs 87.38% <53.84%> (-0.99%) ⬇️
src/common/src/array/bool_array.rs 90.40% <62.50%> (-2.69%) ⬇️
src/common/src/array/primitive_array.rs 87.00% <64.70%> (-2.48%) ⬇️
src/common/src/array/list_array.rs 91.43% <70.00%> (-0.71%) ⬇️
src/common/src/array/bytes_array.rs 84.37% <86.95%> (-0.71%) ⬇️
src/common/src/array/mod.rs 73.52% <100.00%> (+0.50%) ⬆️
src/common/src/buffer/bitmap.rs 95.94% <100.00%> (+0.12%) ⬆️
... and 6 more

📣 We’re building smart automated test selection to slash your CI/CD build times. Learn more

Copy link
Member

@BugenZhao BugenZhao left a comment

Choose a reason for hiding this comment

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

LGTM!!!

src/common/src/array/primitive_array.rs Outdated Show resolved Hide resolved
src/expr/benches/expr.rs Show resolved Hide resolved
Signed-off-by: Runji Wang <wangrunji0408@163.com>
@mergify mergify bot merged commit 00741be into main Dec 13, 2022
@mergify mergify bot deleted the wrj/expr-bench branch December 13, 2022 13:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants