Commit 82a6081
authored
perf[vortex-array]: use from_trusted_len_iter in primitive casts (#7401)
Some of our scan profiles show 10% of scan cpu time is spent in integer
widening casts (nullable dictionary codes). This commit simplifies and
optimizes primitive casts by hoisting a lot of hot loop branching logic.
Specifically, this commit relies on values_fit_in to verify
representability so that we can avoid a potential validity and error
check in the hot loop. Additionally from_trusted_len_iter lets the
destination BufferMut optimize the actual cast instead of using
push_unchecked for each element.
Results locally running the benchmark from #7400. Before:
```
$ cargo bench -p vortex-array --bench cast_primitive
Finished `bench` profile [optimized + debuginfo] target(s) in 0.16s
Running benches/cast_primitive.rs (target/release/deps/cast_primitive-598823f32b8f3db0)
Timer precision: 41 ns
cast_primitive fastest │ slowest │ median │ mean │ samples │ iters
╰─ cast_u16_to_u32 384.2 µs │ 491.6 µs │ 395.1 µs │ 397.3 µs │ 100 │ 100
```
After:
```
cargo bench -p vortex-array --bench cast_primitive
Finished `bench` profile [optimized + debuginfo] target(s) in 0.17s
Running benches/cast_primitive.rs (target/release/deps/cast_primitive-598823f32b8f3db0)
Timer precision: 41 ns
cast_primitive fastest │ slowest │ median │ mean │ samples │ iters
╰─ cast_u16_to_u32 6.874 µs │ 543.7 µs │ 6.999 µs │ 12.7 µs │ 100 │ 100
```
Signed-off-by: Alfonso Subiotto Marques <alfonso.subiotto@polarsignals.com>1 parent 3fd9f26 commit 82a6081
2 files changed
Lines changed: 38 additions & 39 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
9 | 9 | | |
10 | 10 | | |
11 | 11 | | |
| 12 | + | |
12 | 13 | | |
13 | 14 | | |
14 | 15 | | |
| |||
28 | 29 | | |
29 | 30 | | |
30 | 31 | | |
| 32 | + | |
| 33 | + | |
31 | 34 | | |
32 | 35 | | |
33 | 36 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | 1 | | |
2 | 2 | | |
3 | 3 | | |
| 4 | + | |
4 | 5 | | |
5 | 6 | | |
6 | 7 | | |
7 | 8 | | |
8 | | - | |
9 | | - | |
10 | | - | |
11 | 9 | | |
12 | 10 | | |
13 | 11 | | |
| |||
53 | 51 | | |
54 | 52 | | |
55 | 53 | | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
56 | 62 | | |
57 | 63 | | |
58 | 64 | | |
59 | 65 | | |
60 | 66 | | |
61 | 67 | | |
62 | 68 | | |
63 | | - | |
64 | | - | |
65 | | - | |
66 | | - | |
67 | | - | |
68 | | - | |
69 | | - | |
70 | 69 | | |
71 | 70 | | |
72 | 71 | | |
| |||
79 | 78 | | |
80 | 79 | | |
81 | 80 | | |
82 | | - | |
83 | | - | |
84 | | - | |
| 81 | + | |
85 | 82 | | |
86 | 83 | | |
87 | | - | |
88 | | - | |
| 84 | + | |
89 | 85 | | |
90 | 86 | | |
91 | 87 | | |
| |||
104 | 100 | | |
105 | 101 | | |
106 | 102 | | |
107 | | - | |
108 | | - | |
109 | | - | |
110 | | - | |
111 | | - | |
112 | | - | |
113 | | - | |
114 | | - | |
115 | | - | |
116 | | - | |
117 | | - | |
118 | | - | |
119 | | - | |
120 | | - | |
121 | | - | |
122 | | - | |
123 | | - | |
124 | | - | |
125 | | - | |
126 | | - | |
127 | | - | |
128 | | - | |
129 | | - | |
130 | | - | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
131 | 108 | | |
132 | 109 | | |
133 | 110 | | |
| |||
319 | 296 | | |
320 | 297 | | |
321 | 298 | | |
| 299 | + | |
| 300 | + | |
| 301 | + | |
| 302 | + | |
| 303 | + | |
| 304 | + | |
| 305 | + | |
| 306 | + | |
| 307 | + | |
| 308 | + | |
| 309 | + | |
| 310 | + | |
| 311 | + | |
| 312 | + | |
| 313 | + | |
| 314 | + | |
| 315 | + | |
322 | 316 | | |
323 | 317 | | |
324 | 318 | | |
| |||
329 | 323 | | |
330 | 324 | | |
331 | 325 | | |
| 326 | + | |
332 | 327 | | |
| 328 | + | |
333 | 329 | | |
334 | 330 | | |
335 | 331 | | |
| |||
0 commit comments