Skip to content

Skip codegen of unreachable type dispatch arms - #10740

Merged
robert3005 merged 2 commits into
developfrom
rk/size-unreachable-dispatch-arms
Oct 26, 2026
Merged

robert3005 merged 2 commits into
developfrom
rk/size-unreachable-dispatch-arms

Conversation

@robert3005

@robert3005 robert3005 commented Oct 23, 2026 •

Copy link
Copy Markdown
Contributor

A const condition removes the unreachable arms before codegen in three places:

  • check_decimal_identical dispatched 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 than W (all callers pass the wider of two inputs), and the narrowing branch of converted_buffer::<W> only runs for storage types wider than W. Only 15 of 36 arms of each can run.
  • The bit-packed widening cast compiled all 64 integer pairs, but only widening pairs reach the kernel.

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.

release __text (macOS arm64) before after
vortex-array 14,023,548 B 13,933,616 B (-90 KB)
vortex-fastlanes 4,442,156 B 4,331,764 B (-110 KB)

@robert3005 robert3005 added the changelog/chore A trivial change label Oct 23, 2026
@codspeed

codspeed Bot commented Oct 23, 2026 •

Copy link
Copy Markdown

Merging this PR will degrade performance by 12.93%

4 warnings, 1 note

⚠️ Walltime results may be unreliable

Some benchmarks used the Walltime instrument outside CodSpeed Macro Runners, which can make the results inconsistent.

Learn more about Macro Runners

See affected benchmarks

⚠️ Unable to measure the execution of 2 benchmarks

These benchmarks measured no execution time, so their results are not comparable and count as unchanged. This usually happens when the compiler removes the code under test.

Prevent compiler optimizations

See affected benchmarks

⚠️ 21 benchmarks are dominated by system calls

System calls cannot be simulated consistently and are left out of the measure. The reported value understates the real cost. Switch to the Walltime instrument to measure them.

Learn more about system calls

See affected benchmarks

⚠️ Base and head ran on different runner types

Some benchmarks with significant performance changes were compared across different runner types, so the changes might not come from the code. Run base and head on the same runner type, or use CodSpeed Macro Runners for more stable results.

Learn more about Macro Runners

Open the report in CodSpeed to investigate

ℹ️ 40 benchmarks have no flamegraph

The flamegraph wasn't generated: the symbols of the profiling trace could not be resolved, because no information about the language frames was collected.

See affected benchmarks

❌ 2 regressed benchmarks
✅ 2437 untouched benchmarks
⏩ 12 skipped benchmarks1

Warning

Please fix the performance issues or acknowledge them on CodSpeed.

Performance Changes

Mode Benchmark BASE HEAD Efficiency
❌ Walltime threshold_avx2[80] 2.6 µs 3 µs -13.41%
❌ CPU Simulation random_i8[0.01] 101.8 µs 116.3 µs -12.45%

Tip

Investigate this regression by commenting @codspeedbot fix this regression on this PR, or directly use the CodSpeed MCP with your agent.


Comparing rk/size-unreachable-dispatch-arms (95f6de5) with develop (33675d9)

Open in CodSpeed

Footnotes

  1. 12 benchmarks were skipped, so the baseline results were used instead. If they were deleted from the codebase, click here and archive them to remove them from the performance reports. ↩

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>
@robert3005
robert3005 force-pushed the rk/size-unreachable-dispatch-arms branch from dd90465 to f0f1c9e Compare October 26, 2026 16:20
@robert3005
robert3005 enabled auto-merge (squash) October 26, 2026 16:38
@robert3005
robert3005 requested review from mhk197 and myrrc October 26, 2026 17:25
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>
@robert3005
robert3005 requested a review from myrrc October 26, 2026 17:50
@robert3005

Copy link
Copy Markdown
Contributor Author

Ok, there's a better version now

Comment on lines +129 to +133
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()

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this code is pretty strange

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

oh you need the lifetime

builder.finish_into_primitive().into_array()
builder
.finish_into_primitive()
.reinterpret_cast(tgt)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe this can be a followup

@robert3005
robert3005 merged commit 2906490 into develop Oct 26, 2026
115 of 116 checks passed
@robert3005
robert3005 deleted the rk/size-unreachable-dispatch-arms branch October 26, 2026 19:07
connortsui20 added a commit that referenced this pull request Oct 27, 2026
## 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>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

changelog/chore A trivial change

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants