Commit a87bdc9
authored
perf: optimize array_remove for scalar needle (#22390)
## Which issue does this PR close?
<!--
We generally require a GitHub issue to be filed for all bug fixes and
enhancements and this helps us generate change logs for our releases.
You can link an issue to this PR using the GitHub syntax. For example
`Closes #123` indicates that this PR will close issue #123.
-->
- Closes #.
## Rationale for this change
<!--
Why are you proposing this change? If this is already explained clearly
in the issue then this section is not needed.
Explaining clearly why changes are proposed helps reviewers understand
your changes and offer better suggestions for fixes.
-->
Similar to #22387 (array_replace scalar optimization)
`array_remove` / `array_remove_n` / `array_remove_all` perform
element-wise comparison by invoking `compare_element_to_list` against
each row's sub-array individually. When the needle is a scalar, this can
be optimized by performing a single vectorized `distinct` comparison
over the entire flattened values buffer.
## What changes are included in this PR?
- Add a specialized removal kernel (`general_remove_with_scalar`) that
uses `arrow_ord::cmp::distinct` with `Scalar` wrapper for a single bulk
comparison pass over the flat values buffer.
- Extend SLT tests with multi-row scalar-argument coverage,
NULL-containing arrays, empty-array edge cases, boundary `n` values, and
LargeList type coverage.
<!--
There is no need to duplicate the description in the issue here but it
is sometimes worth providing a summary of the individual changes in this
PR.
-->
### Benchmarks
```
group main optimized
----- ---- ---------
array_remove_all_int64/remove/list size: 10, num_rows: 4000 4.35 856.8±97.81µs ? ?/sec 1.00 196.9±4.48µs ? ?/sec
array_remove_all_int64/remove/list size: 100, num_rows: 10000 1.90 5.5±0.09ms ? ?/sec 1.00 2.9±0.09ms ? ?/sec
array_remove_all_int64/remove/list size: 500, num_rows: 10000 1.35 19.2±0.21ms ? ?/sec 1.00 14.2±0.48ms ? ?/sec
array_remove_all_int64_nested/remove/list size: 10, num_rows: 4000 1.00 7.1±0.12ms ? ?/sec 1.04 7.4±0.12ms ? ?/sec
array_remove_all_int64_nested/remove/list size: 100, num_rows: 3000 1.00 36.5±0.39ms ? ?/sec 1.05 38.3±2.61ms ? ?/sec
array_remove_all_int64_nested/remove/list size: 300, num_rows: 1500 1.01 53.5±2.26ms ? ?/sec 1.00 53.0±0.99ms ? ?/sec
array_remove_boolean/remove/list size: 10, num_rows: 4000 3.83 813.9±7.08µs ? ?/sec 1.00 212.4±2.28µs ? ?/sec
array_remove_boolean/remove/list size: 100, num_rows: 10000 2.73 3.7±0.03ms ? ?/sec 1.00 1364.7±177.83µs ? ?/sec
array_remove_boolean/remove/list size: 500, num_rows: 10000 2.34 9.8±0.14ms ? ?/sec 1.00 4.2±0.25ms ? ?/sec
array_remove_fixed_size_binary/remove/list size: 10, num_rows: 4000 3.16 918.2±16.76µs ? ?/sec 1.00 290.6±9.79µs ? ?/sec
array_remove_fixed_size_binary/remove/list size: 100, num_rows: 10000 1.56 6.9±0.13ms ? ?/sec 1.00 4.4±0.15ms ? ?/sec
array_remove_fixed_size_binary/remove/list size: 500, num_rows: 10000 1.17 27.7±0.84ms ? ?/sec 1.00 23.6±2.04ms ? ?/sec
array_remove_int64/remove/list size: 10, num_rows: 4000 4.55 825.7±6.30µs ? ?/sec 1.00 181.3±4.32µs ? ?/sec
array_remove_int64/remove/list size: 100, num_rows: 10000 3.35 3.8±0.11ms ? ?/sec 1.00 1135.6±54.87µs ? ?/sec
array_remove_int64/remove/list size: 500, num_rows: 10000 2.04 10.3±0.35ms ? ?/sec 1.00 5.1±0.39ms ? ?/sec
array_remove_int64_nested/remove/list size: 10, num_rows: 4000 1.00 7.1±0.18ms ? ?/sec 1.02 7.2±0.07ms ? ?/sec
array_remove_int64_nested/remove/list size: 100, num_rows: 3000 1.00 36.1±1.35ms ? ?/sec 1.07 38.5±3.67ms ? ?/sec
array_remove_int64_nested/remove/list size: 300, num_rows: 1500 1.00 51.7±0.57ms ? ?/sec 1.05 54.1±2.13ms ? ?/sec
array_remove_n_int64/remove/list size: 10, num_rows: 4000 4.43 845.3±5.00µs ? ?/sec 1.00 190.6±2.84µs ? ?/sec
array_remove_n_int64/remove/list size: 100, num_rows: 10000 2.29 4.7±0.11ms ? ?/sec 1.00 2.0±0.12ms ? ?/sec
array_remove_n_int64/remove/list size: 500, num_rows: 10000 1.63 14.8±0.42ms ? ?/sec 1.00 9.0±0.51ms ? ?/sec
array_remove_n_int64_nested/remove/list size: 10, num_rows: 4000 1.00 7.0±0.09ms ? ?/sec 1.29 8.9±3.44ms ? ?/sec
array_remove_n_int64_nested/remove/list size: 100, num_rows: 3000 1.00 36.6±0.42ms ? ?/sec 1.03 37.7±0.68ms ? ?/sec
array_remove_n_int64_nested/remove/list size: 300, num_rows: 1500 1.00 52.7±3.68ms ? ?/sec 1.03 54.5±4.49ms ? ?/sec
array_remove_strings/remove/list size: 10, num_rows: 4000 2.50 1144.6±21.95µs ? ?/sec 1.00 457.0±14.15µs ? ?/sec
array_remove_strings/remove/list size: 100, num_rows: 10000 1.42 10.5±1.16ms ? ?/sec 1.00 7.4±0.34ms ? ?/sec
array_remove_strings/remove/list size: 500, num_rows: 10000 1.12 39.8±0.91ms ? ?/sec 1.00 35.5±1.51ms ? ?/sec
```
## Are these changes tested?
<!--
We typically require tests for all PRs in order to:
1. Prevent the code from being accidentally broken by subsequent changes
2. Serve as another way to document the expected behavior of the code
If tests are not included in your PR, please explain why (for example,
are they covered by existing tests)?
-->
Yes, existing and new SLT edge-case tests in `array_remove.slt`.
## Are there any user-facing changes?
No.
<!--
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.
-->1 parent fcc9cc4 commit a87bdc9
2 files changed
Lines changed: 286 additions & 30 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
18 | 18 | | |
19 | 19 | | |
20 | 20 | | |
21 | | - | |
22 | 21 | | |
23 | | - | |
24 | | - | |
| 22 | + | |
| 23 | + | |
25 | 24 | | |
26 | 25 | | |
27 | 26 | | |
28 | 27 | | |
29 | 28 | | |
30 | | - | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
31 | 32 | | |
32 | 33 | | |
33 | 34 | | |
| |||
113 | 114 | | |
114 | 115 | | |
115 | 116 | | |
116 | | - | |
| 117 | + | |
| 118 | + | |
| 119 | + | |
| 120 | + | |
| 121 | + | |
| 122 | + | |
| 123 | + | |
| 124 | + | |
| 125 | + | |
| 126 | + | |
| 127 | + | |
| 128 | + | |
| 129 | + | |
| 130 | + | |
| 131 | + | |
| 132 | + | |
| 133 | + | |
| 134 | + | |
117 | 135 | | |
118 | 136 | | |
119 | 137 | | |
| |||
214 | 232 | | |
215 | 233 | | |
216 | 234 | | |
217 | | - | |
| 235 | + | |
| 236 | + | |
| 237 | + | |
| 238 | + | |
| 239 | + | |
| 240 | + | |
| 241 | + | |
| 242 | + | |
| 243 | + | |
| 244 | + | |
| 245 | + | |
| 246 | + | |
| 247 | + | |
| 248 | + | |
| 249 | + | |
| 250 | + | |
| 251 | + | |
| 252 | + | |
| 253 | + | |
| 254 | + | |
| 255 | + | |
| 256 | + | |
| 257 | + | |
| 258 | + | |
| 259 | + | |
| 260 | + | |
| 261 | + | |
| 262 | + | |
| 263 | + | |
| 264 | + | |
| 265 | + | |
| 266 | + | |
| 267 | + | |
| 268 | + | |
218 | 269 | | |
219 | 270 | | |
220 | 271 | | |
| |||
304 | 355 | | |
305 | 356 | | |
306 | 357 | | |
307 | | - | |
| 358 | + | |
| 359 | + | |
| 360 | + | |
| 361 | + | |
| 362 | + | |
| 363 | + | |
| 364 | + | |
| 365 | + | |
| 366 | + | |
| 367 | + | |
| 368 | + | |
| 369 | + | |
| 370 | + | |
| 371 | + | |
| 372 | + | |
| 373 | + | |
| 374 | + | |
| 375 | + | |
| 376 | + | |
308 | 377 | | |
309 | 378 | | |
310 | 379 | | |
| |||
316 | 385 | | |
317 | 386 | | |
318 | 387 | | |
319 | | - | |
320 | | - | |
321 | | - | |
322 | | - | |
323 | | - | |
324 | | - | |
325 | | - | |
326 | | - | |
327 | | - | |
328 | | - | |
329 | | - | |
330 | | - | |
331 | | - | |
332 | | - | |
333 | | - | |
334 | | - | |
335 | | - | |
336 | | - | |
337 | | - | |
338 | | - | |
339 | | - | |
340 | 388 | | |
341 | 389 | | |
342 | 390 | | |
| |||
357 | 405 | | |
358 | 406 | | |
359 | 407 | | |
| 408 | + | |
| 409 | + | |
| 410 | + | |
| 411 | + | |
| 412 | + | |
| 413 | + | |
| 414 | + | |
| 415 | + | |
| 416 | + | |
| 417 | + | |
| 418 | + | |
| 419 | + | |
| 420 | + | |
| 421 | + | |
| 422 | + | |
| 423 | + | |
| 424 | + | |
| 425 | + | |
| 426 | + | |
| 427 | + | |
| 428 | + | |
| 429 | + | |
360 | 430 | | |
361 | 431 | | |
362 | 432 | | |
| |||
411 | 481 | | |
412 | 482 | | |
413 | 483 | | |
414 | | - | |
| 484 | + | |
| 485 | + | |
| 486 | + | |
| 487 | + | |
| 488 | + | |
415 | 489 | | |
416 | 490 | | |
417 | 491 | | |
| |||
468 | 542 | | |
469 | 543 | | |
470 | 544 | | |
| 545 | + | |
| 546 | + | |
| 547 | + | |
| 548 | + | |
| 549 | + | |
| 550 | + | |
| 551 | + | |
| 552 | + | |
| 553 | + | |
| 554 | + | |
| 555 | + | |
| 556 | + | |
| 557 | + | |
| 558 | + | |
| 559 | + | |
| 560 | + | |
| 561 | + | |
| 562 | + | |
| 563 | + | |
| 564 | + | |
| 565 | + | |
| 566 | + | |
| 567 | + | |
| 568 | + | |
| 569 | + | |
| 570 | + | |
| 571 | + | |
| 572 | + | |
| 573 | + | |
| 574 | + | |
| 575 | + | |
| 576 | + | |
| 577 | + | |
| 578 | + | |
| 579 | + | |
| 580 | + | |
| 581 | + | |
| 582 | + | |
| 583 | + | |
| 584 | + | |
| 585 | + | |
| 586 | + | |
| 587 | + | |
| 588 | + | |
| 589 | + | |
| 590 | + | |
| 591 | + | |
| 592 | + | |
| 593 | + | |
| 594 | + | |
| 595 | + | |
| 596 | + | |
| 597 | + | |
| 598 | + | |
| 599 | + | |
| 600 | + | |
| 601 | + | |
| 602 | + | |
| 603 | + | |
| 604 | + | |
| 605 | + | |
| 606 | + | |
| 607 | + | |
| 608 | + | |
| 609 | + | |
| 610 | + | |
| 611 | + | |
| 612 | + | |
| 613 | + | |
| 614 | + | |
| 615 | + | |
| 616 | + | |
| 617 | + | |
| 618 | + | |
| 619 | + | |
| 620 | + | |
| 621 | + | |
| 622 | + | |
| 623 | + | |
| 624 | + | |
| 625 | + | |
| 626 | + | |
| 627 | + | |
| 628 | + | |
| 629 | + | |
| 630 | + | |
| 631 | + | |
| 632 | + | |
| 633 | + | |
| 634 | + | |
| 635 | + | |
| 636 | + | |
| 637 | + | |
| 638 | + | |
| 639 | + | |
| 640 | + | |
| 641 | + | |
| 642 | + | |
| 643 | + | |
471 | 644 | | |
472 | 645 | | |
473 | 646 | | |
| |||
0 commit comments