Commit 595e614
authored
perf: optimize
## Which issue does this PR close?
N/A
## Rationale for this change
Optimize existing expression.
## What changes are included in this PR?
Added an array fast path for trunc(value, scalar precision) that hoists
10^precision out of the per-element loop and uses a unary kernel instead
of broadcasting the precision and recomputing powi per element.
## Are these changes tested?
Existing tests.
Benchmark (criterion):
- trunc f32 precision array_ 1024: 87.531% faster (base 1284ns -> cand
160ns)
- trunc f64 precision array_ 1024: 81.29% faster (base 1313ns -> cand
245ns)
- trunc f32 precision array_ 4096: 91.021% faster (base 4542ns -> cand
407ns)
- trunc f64 precision array_ 4096: 82.983% faster (base 4560ns -> cand
776ns)
- trunc f32 precision array_ 8192: 92.235% faster (base 9475ns -> cand
735ns)
- trunc f64 precision array_ 8192: 81.919% faster (base 10319ns -> cand
1865ns)
Full criterion output:
```text
trunc f64 precision array: 1024
time: [245.17 ns 245.40 ns 245.70 ns]
change: [−81.321% −81.290% −81.259%] (p = 0.00 < 0.05)
Performance has improved.
Found 3 outliers among 100 measurements (3.00%)
2 (2.00%) high mild
1 (1.00%) high severe
trunc f32 precision array: 1024
time: [159.81 ns 160.13 ns 160.65 ns]
change: [−87.558% −87.531% −87.495%] (p = 0.00 < 0.05)
Performance has improved.
Found 15 outliers among 100 measurements (15.00%)
6 (6.00%) high mild
9 (9.00%) high severe
trunc f64 precision array: 4096
time: [764.34 ns 768.58 ns 773.05 ns]
change: [−83.091% −82.983% −82.845%] (p = 0.00 < 0.05)
Performance has improved.
Found 8 outliers among 100 measurements (8.00%)
2 (2.00%) high mild
6 (6.00%) high severe
trunc f32 precision array: 4096
time: [404.97 ns 405.35 ns 405.93 ns]
change: [−91.049% −91.021% −90.991%] (p = 0.00 < 0.05)
Performance has improved.
Found 13 outliers among 100 measurements (13.00%)
2 (2.00%) high mild
11 (11.00%) high severe
trunc f64 precision array: 8192
time: [1.8676 µs 1.8741 µs 1.8813 µs]
change: [−81.960% −81.919% −81.874%] (p = 0.00 < 0.05)
Performance has improved.
Found 1 outliers among 100 measurements (1.00%)
1 (1.00%) high mild
trunc f32 precision array: 8192
time: [729.32 ns 731.77 ns 734.41 ns]
change: [−92.264% −92.235% −92.203%] (p = 0.00 < 0.05)
Performance has improved.
Found 6 outliers among 100 measurements (6.00%)
6 (6.00%) high mild
```
## Are there any user-facing changes?
<!--
If there are user-facing changes then we may require documentation to be
updated before approving the PR.
-->
<!--
If there are any breaking changes to public APIs, please add the `api
change` label.
-->trunc for scalar precision case (10x faster) (#23593)1 parent 12fe9a0 commit 595e614
3 files changed
Lines changed: 149 additions & 7 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
301 | 301 | | |
302 | 302 | | |
303 | 303 | | |
| 304 | + | |
| 305 | + | |
| 306 | + | |
| 307 | + | |
| 308 | + | |
304 | 309 | | |
305 | 310 | | |
306 | 311 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
25 | 25 | | |
26 | 26 | | |
27 | 27 | | |
28 | | - | |
29 | | - | |
| 28 | + | |
| 29 | + | |
30 | 30 | | |
31 | 31 | | |
32 | 32 | | |
| |||
40 | 40 | | |
41 | 41 | | |
42 | 42 | | |
43 | | - | |
| 43 | + | |
44 | 44 | | |
45 | 45 | | |
46 | 46 | | |
| |||
158 | 158 | | |
159 | 159 | | |
160 | 160 | | |
| 161 | + | |
| 162 | + | |
| 163 | + | |
| 164 | + | |
| 165 | + | |
| 166 | + | |
161 | 167 | | |
162 | 168 | | |
163 | 169 | | |
| |||
231 | 237 | | |
232 | 238 | | |
233 | 239 | | |
| 240 | + | |
| 241 | + | |
| 242 | + | |
| 243 | + | |
| 244 | + | |
| 245 | + | |
| 246 | + | |
| 247 | + | |
| 248 | + | |
| 249 | + | |
| 250 | + | |
| 251 | + | |
| 252 | + | |
| 253 | + | |
| 254 | + | |
| 255 | + | |
| 256 | + | |
| 257 | + | |
| 258 | + | |
234 | 259 | | |
235 | 260 | | |
236 | 261 | | |
| |||
375 | 400 | | |
376 | 401 | | |
377 | 402 | | |
378 | | - | |
379 | | - | |
| 403 | + | |
| 404 | + | |
| 405 | + | |
| 406 | + | |
380 | 407 | | |
381 | 408 | | |
382 | 409 | | |
| 410 | + | |
| 411 | + | |
| 412 | + | |
| 413 | + | |
| 414 | + | |
| 415 | + | |
| 416 | + | |
| 417 | + | |
| 418 | + | |
| 419 | + | |
| 420 | + | |
| 421 | + | |
| 422 | + | |
| 423 | + | |
| 424 | + | |
| 425 | + | |
| 426 | + | |
| 427 | + | |
| 428 | + | |
| 429 | + | |
383 | 430 | | |
384 | | - | |
385 | | - | |
| 431 | + | |
386 | 432 | | |
387 | 433 | | |
388 | 434 | | |
| |||
0 commit comments