-
Notifications
You must be signed in to change notification settings - Fork 613
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(encoding): add estimate size for value encoding #8692
Conversation
fn estimate_encoded_scalar_size(value: ScalarRefImpl<'_>) -> usize { | ||
match value { | ||
ScalarRefImpl::Int16(_) => 2, | ||
ScalarRefImpl::Int32(_) => 4, | ||
ScalarRefImpl::Int64(_) => 8, | ||
ScalarRefImpl::Serial(_) => 8, | ||
ScalarRefImpl::Float32(_) => 4, | ||
ScalarRefImpl::Float64(_) => 8, | ||
ScalarRefImpl::Utf8(v) => v.as_bytes().len(), | ||
ScalarRefImpl::Bytea(v) => estimate_encoded_str_size(v), | ||
ScalarRefImpl::Bool(_) => 1, | ||
ScalarRefImpl::Decimal(_) => estimate_encoded_decimal_size(), | ||
ScalarRefImpl::Interval(_) => estimate_encoded_interval_size(), | ||
ScalarRefImpl::NaiveDate(_) => estimate_encoded_naivedate_size(), | ||
ScalarRefImpl::NaiveDateTime(_) => estimate_encoded_naivedatetime_size(), | ||
ScalarRefImpl::NaiveTime(_) => estimate_encoded_naivetime_size(), | ||
ScalarRefImpl::Jsonb(_) => 8, | ||
ScalarRefImpl::Struct(s) => estimate_encoded_struct_size(s), | ||
ScalarRefImpl::List(v) => estimate_encoded_list_size(v), | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
maybe we can refactor it with macro or other techs in future PRs.
Codecov Report
@@ Coverage Diff @@
## main #8692 +/- ##
==========================================
+ Coverage 71.06% 71.07% +0.01%
==========================================
Files 1166 1166
Lines 192345 192454 +109
==========================================
+ Hits 136691 136792 +101
- Misses 55654 55662 +8
Flags with carried forward coverage won't be shown. Click here to find out more.
... and 8 files with indirect coverage changes 📣 We’re building smart automated test selection to slash your CI/CD build times. Learn more |
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please add test
You can write some datums, encode them, and compare with your pre-calculated result. |
we can not get the exact size for the jsonb 😿 |
Co-authored-by: TennyZhuang <zty0826@gmail.com>
if let Some(d) = datum_ref.to_datum_ref() { | ||
1 + estimate_serialize_scalar_size(d) | ||
} else { | ||
1 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I guess 1
here is to store the null u8 flag?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes
ScalarRefImpl::NaiveDate(_) => estimate_serialize_naivedate_size(), | ||
ScalarRefImpl::NaiveDateTime(_) => estimate_serialize_naivedatetime_size(), | ||
ScalarRefImpl::NaiveTime(_) => estimate_serialize_naivetime_size(), | ||
ScalarRefImpl::Jsonb(_) => 8, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this a mistake? @st1page
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It’s heavy to pre-compute the size of jsonb, but anyway, 8 is too small and we need some comments here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🤔 I will leave an issue to bench and trade-off if it is worth estimating the jsonb's size. @st1page
I hereby agree to the terms of the RisingWave Labs, Inc. Contributor License Agreement.
What's changed and what's your intention?
add function to estimate the value encoding size of the datum
prepare for #8683
Checklist For Contributors
./risedev check
(or alias,./risedev c
)Checklist For Reviewers
Documentation
Click here for Documentation
Types of user-facing changes
Please keep the types that apply to your changes, and remove the others.
Release note