Repository navigation
feat(arrow-cast): optimize decimal to float casts - #12462
Surajsuthar wants to merge 4 commits into
Conversation
|
@Jefffrey Hey, could u look out |
Jefffrey
left a comment
There was a problem hiding this comment.
do we have some benchmark numbers to show this is a performance improvement?
| /// Integers at or below 2^53 convert to an `f64` exactly. | ||
| const F64_EXACT_INT_LIMIT: i64 = 1 << 53; | ||
| /// Integers at or below 2^24 convert to an `f32` exactly. | ||
| const F32_EXACT_INT_LIMIT: i64 = 1 << 24; |
There was a problem hiding this comment.
why are we turning these to i64s from f64s?
There was a problem hiding this comment.
only to compared with the original decimal integer value before converting it to f64
| return value; | ||
| } | ||
|
|
||
| unscaled / 10_f64.powi(scale.into()) |
There was a problem hiding this comment.
in what cases can this fail?
There was a problem hiding this comment.
write_decimal can fail if the fixed buffer is insufficient, lexical_core::parse can fail if the bytes are not a valid floating-point literal, but i think valid Arrow decimal values and the current buffer size neither is expected to fail and fallback preserves can previous behavior without panicking.
| { | ||
| let array = array.as_primitive::<D>(); | ||
|
|
||
| if scale == 0 { |
There was a problem hiding this comment.
why are we adding a separate path for scale 0 here?
There was a problem hiding this comment.
so reason i separate this path only for that if scale is 0 then integer-to-float can directly converted without any additional work no div, mul, power calculation, or per-value scale branch is needed, we could add on slow path as well wont make much difference
mainly it improves the large-decimal fallback path by avoiding the intermediate String allocation (which were previously doing |
|
run benchmark format_decimal |
|
Hi @Surajsuthar, thanks for the request (#12462 (comment)). Only whitelisted users can trigger benchmarks. Allowed users: 2010YOUY01, Dandandan, Fokko, Jefffrey, Omega359, Rachelint, Rich-T-kid, adriangb, alamb, andygrove, asubiotto, avantgardnerio, brunal, buraksenn, cetra3, codephage2020, coderfender, comphead, erenavsarogullari, etseidl, friendlymatthew, gabotechs, geoffreyclaude, grtlr, gruuya, haohuaijin, jayzhan211, jonathanc-n, kevinjqliu, klion26, kosiew, kumarUjjawal, kunalsinghdadhwal, liamzwbao, mbutrovich, mkleen, mzabaluev, neilconway, rluvaton, sdf-jkl, timsaucer, xudong963, zhuqi-lucas. File an issue against this benchmark runner |
Which issue does this PR close?
Rationale for this change
What changes are included in this PR?
Are these changes tested?
yes
cargo test -p arrow-castAre there any significant user-facing changes?
AI usage disclosure