Repository navigation
perf: cut per-row work in native cast kernels - #7631
Conversation
andygrove
left a comment
There was a problem hiding this comment.
Thanks @coderfender, these are nice wins. I ran the benches on x86 (Ryzen 9 7950X3D) against the merge base in two alternating rounds, and I see no regressions. Boolean casts are at 0.25x to 0.42x, int to decimal at 0.33x to 0.38x, and float to decimal at dec(15,4) at about 0.71x.
I also added dec(19,4) and dec(38,10) cases, and those stay at 0.97x to 0.99x because they still go through to_i128. I don't think the precision <= 18 check is needed in cast_floating_point_to_decimal128. That branch is only reached when (x - r).abs() + x.abs() * TIE_GUARD < 0.5, and with TIE_GUARD = 2^-48 that already means |x| < 2^47. So r as i64 is exact at any precision. Could you drop fits_i64 and always convert through i64? Then high-precision targets get the same speedup. The i64 vs i128 test could compare against to_i128 directly instead of against precision 19.
Which issue does this PR close?
Part of #5128.
Rationale for this change
Several cast kernels did avoidable per-row work.
What changes are included in this PR?
write_i8: format from a stack buffer instead ofwrite!per byte.i64instead ofto_i128.String.Untouched cases stay within noise (1.00 to 1.02).
critcmp (main vs this PR)
Overlaps #7528 in
cast_int_to_decimal128_internal; merges cleanly, best landed after it.How are these changes tested?
New unit tests:
write_i8for all 256 bytes, sliced arrays with null rows, int to decimal at the type boundaries in every eval mode, boolean casts against Arrow's cast, and float to decimal with thei64path against thei128one.