Repository navigation
Commit 1b28996
authored
perf(array): hoist decimal same-scale cast plan (#8932)
## Summary
- Evaluate the `SameScale` cast plan once for each array.
- Use a direct closure for each value in a same-scale cast.
- Use `cast_decimal_buffer` for dense, null, and masked output buffers.
- Keep the existing operation for all other cast plans.
## Problem
The previous code called `DecimalCastPlan::cast` for each value. That
function matched the cast plan for each value.
The benchmark profile uses 16 code-generation units and no LTO. An
unrelated source addition changed the LLVM output for this function. The
nullable copy benchmark increased from approximately 65 µs to 99 µs.
Samply showed the same hot call path in both binaries:
```text
try_map_masked_into -> DecimalCastPlan::cast
```
The slow binary used a larger function and more stack loads and stores.
The new code moves the common plan match outside the value loop. This
makes the loop independent of that match.
## Benchmarks
Command:
```console
cargo bench -p vortex-array --bench cast_decimal -- --sample-count 100 --min-time 3 --max-time 6 --color never
```
| benchmark | develop median | this PR median | change |
|---|---:|---:|---:|
| `copy_non_nullable[65536]` | 70.10 µs | 41.18 µs | -41.3% |
| `copy_nullable[65536]` | 65.11 µs | 56.44 µs | -13.3% |
| `in_place_non_nullable[65536]` | 590.5 ns | 610.7 ns | +20.2 ns |
| `in_place_nullable[65536]` | 680.5 ns | 690.7 ns | +10.2 ns |
The in-place cases do not use the changed buffer path. Their differences
are 10 ns and 20 ns.
## Verification
- `cargo nextest run -p vortex-array -E
'test(/arrays::decimal::compute::cast::tests/)'` — 23 passed
- `cargo clippy --all-targets --all-features`
- `cargo +nightly fmt --all --check`
## AI assistance
This PR was prepared with OpenAI Codex. The human author reviewed the
code, benchmark results, profile data, and test results.
Signed-off-by: 蔡略 <[email protected]>1 parent 640d802 commit 1b28996
1 file changed
Lines changed: 37 additions & 30 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
216 | 216 | | |
217 | 217 | | |
218 | 218 | | |
219 | | - | |
| 219 | + | |
| 220 | + | |
| 221 | + | |
| 222 | + | |
| 223 | + | |
| 224 | + | |
| 225 | + | |
| 226 | + | |
| 227 | + | |
| 228 | + | |
| 229 | + | |
| 230 | + | |
220 | 231 | | |
221 | | - | |
| 232 | + | |
| 233 | + | |
| 234 | + | |
| 235 | + | |
| 236 | + | |
| 237 | + | |
| 238 | + | |
| 239 | + | |
| 240 | + | |
| 241 | + | |
| 242 | + | |
| 243 | + | |
| 244 | + | |
| 245 | + | |
222 | 246 | | |
223 | | - | |
224 | | - | |
225 | | - | |
226 | | - | |
227 | | - | |
228 | | - | |
229 | | - | |
230 | | - | |
231 | | - | |
232 | | - | |
233 | | - | |
| 247 | + | |
234 | 248 | | |
235 | | - | |
| 249 | + | |
236 | 250 | | |
237 | | - | |
238 | | - | |
239 | | - | |
240 | | - | |
241 | | - | |
242 | | - | |
243 | | - | |
244 | | - | |
245 | | - | |
246 | | - | |
247 | | - | |
248 | | - | |
249 | | - | |
| 251 | + | |
| 252 | + | |
| 253 | + | |
| 254 | + | |
| 255 | + | |
250 | 256 | | |
251 | | - | |
252 | | - | |
253 | | - | |
| 257 | + | |
| 258 | + | |
| 259 | + | |
| 260 | + | |
254 | 261 | | |
255 | 262 | | |
256 | 263 | | |
| |||
0 commit comments