-
Notifications
You must be signed in to change notification settings - Fork 796
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: Faster decimal precision overflow checks #6419
perf: Faster decimal precision overflow checks #6419
Conversation
let max = MAX_DECIMAL_FOR_EACH_PRECISION[usize::from(precision) - 1]; | ||
let min = MIN_DECIMAL_FOR_EACH_PRECISION[usize::from(precision) - 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 believe that this is where the memcpy
was being introduced
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.
Hmm, this is interesting. By assigning a new variable, it did memory copying of the i128 value.
fn is_valid_decimal_precision(value: Self::Native, precision: u8) -> bool { | ||
is_validate_decimal_precision(value, precision) | ||
} |
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 used to avoid creating ArrowError
and the error string for the cases that we don't need the error?
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
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.
thanks @andygrove
probably a nit: I can see usize::from(precision) - 1
a lot which require new allocation of usize.
My feeling the precision is static? may we can precompute idx and pass it by reference?
Co-authored-by: Liang-Chi Hsieh <viirya@gmail.com>
What if we just insert an extra element in the start of each of the lookup arrays and then just use |
…arrow-rs into faster-decimal-overflow-check
Updated benchmark results after removing the
|
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.
lgtm thanks @andygrove
I reverted the API change |
I'm okay with the PR, although the array that changed moved to crate visibility and doesn't seem to affect others, however I'm not sure if anyone else other than arrow-rs actually used it |
I reverted the change to the original array and added a copy with the extra element so as not to break the current API. The new array is |
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.
Nice
Which issue does this PR close?
N/A
Rationale for this change
Small performance optimization.
What changes are included in this PR?
I noticed two areas of overhead in the current approach to verifying decimal precision.
I tested the following variations of the decimal precision check in Rust playground.
validate_decimal_precision1
avoids amemcpy
that appears invalidate_decimal_precision2
:Are there any user-facing changes?
Technically, this is an API change because I made two consts
pub(crate)
instead ofpub
. However, if anyone wants access to the original consts they could just copy them into their code base.