Skip to content

Keep same-scale decimal widening casts lazy - #11006

Draft
connortsui20 wants to merge 1 commit into
ct/decimal-widen-storedfrom
ct/decimal-widen-lazy-cast
Draft

connortsui20 wants to merge 1 commit into
ct/decimal-widen-storedfrom
ct/decimal-widen-lazy-cast

Conversation

@connortsui20

@connortsui20 connortsui20 commented Oct 29, 2026 •

Copy link
Copy Markdown
Member

Tracking Issue: #10701

Top of the decimal Widen stack, on #11005. No release gate.

Summary

A same-scale decimal cast that grows the canonical width copied every value into the wider type, even when the caller never reads them all. It now returns a decimal Widen over the source, so the copy waits for execution, and compute after the cast runs on the narrow values. This is the first production code that builds a decimal Widen, so it lands after the serializer lowering (#11002) and the kernels (#11003, #11004).

Changes

The child keeps the statistics of the source, such as exact extrema, because it holds the same values. A cast of a decimal Widen passes to its child. Widen execution copies decimal values instead of yielding a cast, which also keeps it from yielding a cast that returns a Widen again. A test checks that the default file writer round-trips a decimal Widen.

Known cost: filter at precision 38 is slower on a Widen than on the canonical array (see #10946), and a cast result now takes that path.

Local benchmark results

cargo bench -p vortex-array --bench widen_decimal, Apple M4, medians. The numbers were measured at the top of this stack before the split, so they cover the whole stack, not this layer alone. The baseline is the canonical input, and the candidate is the same values as a Widen (child precision 5 under precision 10, 9 under 18, and 18 under 38). CodSpeed on this PR measures the layer itself.

bench p10 canonical p10 Widen p18 canonical p18 Widen p38 canonical p38 Widen
cast_widen 12.08 µs 6.958 µs 12.33 µs 6.958 µs 16.54 µs 14.58 µs

API Changes

Casting a DecimalArray to a higher precision at the same scale returns a Widen when the canonical width grows.

A same-scale cast that grows the canonical width copied every value
into the wider type, even when the caller never reads them all. Return
a decimal Widen over the source instead, whose dtype is a true label
for its values, so the copy waits for execution. The child also keeps
the statistics of the source, such as exact extrema, because it holds
the same values. A cast of a decimal Widen passes to its child.

This is the first production code that builds a decimal Widen. Widen
execution already copies decimal values instead of yielding a cast,
which now also keeps it from yielding a cast that returns a Widen
again. A test checks that the default file writer round-trips a
decimal Widen.

Signed-off-by: Connor Tsui <[email protected]>
@codspeed

codspeed Bot commented Oct 29, 2026

Copy link
Copy Markdown

Merging this PR will regress 1 benchmark

2 warnings

⚠️ 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

⚠️ 1 benchmark is 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

⚡ 12 improved benchmarks
❌ 1 regressed benchmark
✅ 2347 untouched benchmarks

Warning

Please fix the performance issues or acknowledge them on CodSpeed.

Performance Changes

Mode Benchmark BASE HEAD Efficiency
❌ CPU Simulation filter_powerlaw_by_random[10000] 700.5 ns 787.9 ns -11.09%
⚡ CPU Simulation cast_widen[p38_childp18_widen] 2.9 ms 1.5 ms +95.98%
⚡ CPU Simulation widen_nullable[16384] 358.4 µs 225.4 µs +59.03%
⚡ Walltime filter_neon[64] 2.9 µs 1.9 µs +57.4%
⚡ CPU Simulation cast_widen[p10_childp5_widen] 1,210.9 µs 789.8 µs +53.32%
⚡ CPU Simulation cast_widen[p18_childp9_widen] 1,211 µs 790.2 µs +53.26%
⚡ Walltime threshold_neon[64] 3.7 µs 2.6 µs +41.85%
⚡ Walltime filter_neon[80] 3.7 µs 2.7 µs +40.45%
⚡ CPU Simulation cast_widen[p38_childp18_canonical] 2.4 ms 1.8 ms +31.49%
⚡ Walltime threshold_neon[80] 4.3 µs 3.5 µs +22.42%
⚡ CPU Simulation take_filter_primitive_small_uncached_random_mask_random_indices[4096, 10] 24.3 µs 21.6 µs +12.21%
⚡ CPU Simulation cast_widen[p18_childp9_canonical] 1,007.7 µs 913.2 µs +10.35%
⚡ CPU Simulation cast_widen[p10_childp5_canonical] 1,008.2 µs 913.7 µs +10.35%

Tip

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


Comparing ct/decimal-widen-lazy-cast (c0ec9ab) with ct/decimal-widen-stored (eb6bfc5)

Open in CodSpeed

@connortsui20 connortsui20 added the changelog/performance A performance improvement label Oct 29, 2026

This branch has not been deployed

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

Labels

changelog/performance A performance improvement

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant