Repository navigation
Skip codegen of unreachable type dispatch arms - #10740
Conversation
Merging this PR will degrade performance by 12.93%4 warnings, 1 note
Warning Please fix the performance issues or acknowledge them on CodSpeed. Performance Changes
Tip Investigate this regression by commenting Comparing Footnotes
|
Three dispatches compiled kernels for type combinations that an invariant makes unreachable: - check_decimal_identical dispatched on lhs, rhs and their widest type, but the widest type is fixed by the two distinct inputs. - widened_buffer is called only for storage types narrower than W, and the narrowing branch of converted_buffer only for wider ones. - The bit-packed widening cast compiled every integer pair, but only widening pairs reach the kernel. A const condition now removes the other arms before codegen. Also, bit-packing rejects negative values, so the bit-packed cast now views signed sources as unsigned and reinterprets the result. Signed and unsigned casts of the same widths share one kernel. Release __text: vortex-array 14,023,548 -> 13,933,616 bytes (-90 KB), vortex-fastlanes 4,442,156 -> 4,331,764 bytes (-110 KB). Signed-off-by: Robert Kruszewski <github@robertk.io> Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
dd90465 to
f0f1c9e
Compare
Remove `unsigned_view_of`. The signed source now goes through `build_with_validity` with the unsigned ptype of the same width. The patch values are never negative, so their lazy cast cannot fail, and the patches are not executed before the unpack. Signed-off-by: Robert Kruszewski <github@robertk.io> Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
Ok, there's a better version now |
| let unsigned; | ||
| let source = if src.is_signed_int() { | ||
| let unsigned_dtype = DType::Primitive(src.to_unsigned(), array.dtype().nullability()); | ||
| unsigned = build_with_validity(array, bit_width, &unsigned_dtype, array.validity()?)?; | ||
| unsigned.as_view() |
There was a problem hiding this comment.
this code is pretty strange
| builder.finish_into_primitive().into_array() | ||
| builder | ||
| .finish_into_primitive() | ||
| .reinterpret_cast(tgt) |
There was a problem hiding this comment.
I wonder if we should do this in more places? if we know we are dispatching over the structure of data instead of values, we could have a much simpler macro that then reinterpret casts at the end?
There was a problem hiding this comment.
maybe this can be a followup
## Summary Follow-up to #10740. Kernels that only copy or compare stored bits can share code across signed, unsigned, and floating-point types of the same width. ## Changes - Add typed width adapters that forward to a shared power-of-two byte-width dispatcher. - Use byte records in primitive patch, zip, fill-null, interleave, and is-constant kernels, plus shared fixed-width take/filter and filtered take. - Add tests for dispatch contracts, floating-point bit patterns, buffer ownership, and decimal alignment. ## API Changes `match_each_ptype_width!`, `match_each_decimal_type_width!`, and `match_each_power_of_two_width!` bind a `const W: usize`, with an explicit fallback for unsupported widths and an optional specialization list. Validation: pinned nightly formatting, scoped Clippy with all targets and features and `-D warnings`, 100 focused tests, and seven width doctests pass. <details> <summary>Code size comparison</summary> Compared base `a59294e35e` with `77a96de1c0` using separate checkouts and target directories. Both use rustc 1.99.1, LLVM 23.1.1, `aarch64-apple-darwin`, the release profile (opt-level 3, one codegen unit, LTO off), package default features, and the repository's frame-pointer flag. Machine-code bytes from Mach-O `__text` sections: | Artifact | Base | PR | Change | | --- | ---: | ---: | ---: | | `vortex-buffer` library | 34,448 | 34,448 | 0 | | `vortex-array` library | 11,646,740 | 11,508,116 | -138,624 (-1.19%) | | `vortex-fastlanes` library | 2,719,444 | 2,719,444 | 0 | | Linked `vx` binary | 74,396,028 | 74,357,628 | -38,400 (-0.052%) | The linked `vx` file also shrinks from 120,844,528 to 120,779,936 bytes (-64,592). Library totals exclude Rust metadata. Small archive increases in `vortex-buffer` and `vortex-fastlanes` come from metadata, while their machine sections are unchanged. Commands run in each checkout: ```sh cargo build --release --locked -p vortex-buffer -p vortex-array -p vortex-fastlanes --message-format=json-render-diagnostics cargo build --release --locked -p vortex-tui --bin vx --message-format=json-render-diagnostics llvm-size --format=sysv --radix=10 <artifact> ``` These measurements cover this target and profile. Runtime benchmarks were not run locally. </details> --------- Signed-off-by: Connor Tsui <connor.tsui20@gmail.com> Signed-off-by: Claude <noreply@anthropic.com> Co-authored-by: Claude <noreply@anthropic.com>
A const condition removes the unreachable arms before codegen in three places:
check_decimal_identicaldispatched on the lhs storage type, the rhs storage type and their widest type. The two distinct inputs fix the widest type, so only 30 of 216 arms can run.widened_buffer::<W>is only called for storage types narrower thanW(all callers pass the wider of two inputs), and the narrowing branch ofconverted_buffer::<W>only runs for storage types wider thanW. Only 15 of 36 arms of each can run.Bit-packing rejects negative values, so sign extension of a packed value is the same as zero extension. The bit-packed cast now views a signed source as unsigned (the packed buffer is shared and the patch values are reinterpreted) and reinterprets the result to the target type. Signed and unsigned casts of the same widths share one kernel, so the cast compiles 6 kernels instead of 18 reachable ones.
__text(macOS arm64)vortex-arrayvortex-fastlanes