Skip to content

Add native decimal Add/Sub kernels#8724

Draft
mhk197 wants to merge 3 commits into
developfrom
mk/decimal-add-sub
Draft

Add native decimal Add/Sub kernels#8724
mhk197 wants to merge 3 commits into
developfrom
mk/decimal-add-sub

Conversation

@mhk197

@mhk197 mhk197 commented Jul 11, 2026

Copy link
Copy Markdown
Contributor

Adds shared infrastructure for Decimal arithmetic and Add/Sub kernels.

Semantics

Both operands must share one DecimalDType (as compare requires since #8661; coerce_args/least_supertype already coerce to a common decimal dtype), and the result keeps that dtype with unioned nullability. Add/Sub apply to the unscaled stored integers — exact at a shared scale.

Implementation

  • numeric.rs splits into numeric/{mod,primitive,decimal,tests}.rs, mirroring the compare split in Implement compare in vortex instead of falling back to arrow #8661. The generic checked lane loops move to numeric/mod.rs with bounds relaxed to T: Default so wider decimal types qualify.
  • numeric/decimal.rs follows compare/decimal.rs: operands canonicalize through execute::<DecimalArray> (so Chunked, DecimalByteParts, Dict, … work with no kernel registration) or extract constants, widen once to a working type, and run one-pass checked lanes.
  • The working width is max(storage widths, smallest type for p+1 digits), so in-precision inputs cannot spuriously overflow the sum, and the range check subsumes width overflow. Note precision can be stricter than width: 60 + 60 fits an i8 but exceeds precision 2 and errors.
  • The result keeps the working width; DecimalData explicitly supports wider-than-necessary storage. Happy to add a BigCast narrowing pass if preferred.
  • The binary-numeric conformance harness accepts decimals, checking Add/Sub element-wise against DecimalScalar::checked_binary_numeric (whose Add/Sub are already correct) for constants 0, 1, -1, 10^s, MAX_BY_PRECISION[p] in both operand orders; wired into the decimal, chunked, and decimal-byte-parts compute tests.
  • widened_buffer moves from compare/decimal.rs to arrays/decimal so compare and numeric share it.

mhk197 added 3 commits July 10, 2026 17:54
Mechanical move mirroring the compare split: dtype-generic lane machinery
stays in numeric/mod.rs (bounds relaxed to T: Default so wider decimal types
can reuse it), primitive-specific code moves to numeric/primitive.rs, tests
to numeric/tests.rs.

Signed-off-by: Matt Katz <mhkatz97@gmail.com>
Add and Sub over decimal arrays sharing a decimal dtype, applied to the
unscaled stored integers (exact at a shared scale) in a working width wide
enough that in-precision inputs cannot spuriously overflow. Precision
violations error only on valid lanes, matching primitive semantics. Mul and
Div need rescaling and are gated off until follow-up PRs. widened_buffer
moves to arrays/decimal so compare and numeric share it.

Signed-off-by: Matt Katz <mhkatz97@gmail.com>
The conformance harness now accepts decimal arrays, checking Add/Sub results
element-wise against DecimalScalar::checked_binary_numeric for representative
constants. Wire it into the decimal, chunked, and decimal-byte-parts compute
tests, and add decimal Add cases to the binary_ops benchmark.

Signed-off-by: Matt Katz <mhkatz97@gmail.com>
@codspeed-hq

codspeed-hq Bot commented Jul 11, 2026

Copy link
Copy Markdown

Merging this PR will improve performance by 12.73%

⚡ 6 improved benchmarks
❌ 1 regressed benchmark
✅ 1630 untouched benchmarks
🆕 2 new benchmarks
⏩ 38 skipped benchmarks1

Warning

Please fix the performance issues or acknowledge them on CodSpeed.

Performance Changes

Mode Benchmark BASE HEAD Efficiency
Simulation rebuild_naive 91.3 µs 109.3 µs -16.53%
Simulation bitwise_not_vortex_buffer_mut[128] 244.4 ns 186.1 ns +31.34%
Simulation bitwise_not_vortex_buffer_mut[1024] 304.7 ns 246.4 ns +23.68%
Simulation bitwise_not_vortex_buffer_mut[2048] 398.6 ns 340.3 ns +17.14%
Simulation encode_varbin[(10000, 2)] 977.1 µs 835.6 µs +16.94%
Simulation chunked_varbinview_into_canonical[(100, 100)] 307.4 µs 272.1 µs +12.96%
Simulation encode_varbin[(1000, 512)] 210.7 µs 191 µs +10.28%
🆕 Simulation add_decimal_i128_nullable N/A 6.8 ms N/A
🆕 Simulation add_decimal_i64_nonnull N/A 3 ms N/A

Tip

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


Comparing mk/decimal-add-sub (e3fdf45) with develop (d2b2378)

Open in CodSpeed

Footnotes

  1. 38 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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant