Commit ae796ab
authored
## Which issue does this PR close?
- Closes apache#21813.
## Rationale for this change
This PR implements two optimizations for `lower` and `upper` on ASCII
strings:
1. For the `Utf8`/`LargeUtf8` code path, we previously did the case
conversion via `str::to_uppercase` or `str::to_lowercase`. For ASCII
inputs, it is faster to use `map(u8::to_ascii_lowercase).collect()` over
the bytes of the string directly: although the stdlib functions are
well-optimized, they need to check again on every string to see if it is
ASCII. Since we know the input is all-ASCII, we can avoid that check.
2. The `Utf8View` code path previously wasn't optimized for ASCII
strings; add a new code path that is. As with the `Utf8` code path, we
can do case-conversion on bytes directly, which vectorizes well and
avoids repeated ASCII checks. In addition, we can build the output
`StringViewArray` directly, which avoids the intermediate strings and
unnecessary allocations used in the previous approach.
Benchmarks (ARM64):
upper
- upper_all_values_are_ascii: 5.4 → 4.1 µs (−24.1%)
lower — all-ASCII (the optimized paths)
- lower_all_values_are_ascii: 1024: 5.4 → 4.0 µs (−25.9%)
- lower_all_values_are_ascii: 4096: 22.6 → 15.6 µs (−31.0%)
- lower_all_values_are_ascii: 8192: 41.9 → 30.8 µs (−26.5%)
- string_views size:4096 str_len:10 null:0 mixed:false: 151.0 → 75.3 µs
(−50.1%)
- string_views size:4096 str_len:10 null:0 mixed:true: 175.9 → 134.6 µs
(−23.5%)
- string_views size:4096 str_len:10 null:0.1 mixed:false: 143.5 → 76.8
µs (−46.5%)
- string_views size:4096 str_len:10 null:0.1 mixed:true: 166.6 → 125.0
µs (−25.0%)
- string_views size:4096 str_len:64 null:0 mixed:false: 150.1 → 92.7 µs
(−38.2%)
- string_views size:4096 str_len:64 null:0 mixed:true: 185.2 → 140.1 µs
(−24.4%)
- string_views size:4096 str_len:64 null:0.1 mixed:false: 136.7 → 97.0
µs (−29.0%)
- string_views size:4096 str_len:64 null:0.1 mixed:true: 173.7 → 131.2
µs (−24.5%)
- string_views size:4096 str_len:128 null:0 mixed:false: 190.3 → 141.7
µs (−25.5%)
- string_views size:4096 str_len:128 null:0 mixed:true: 197.0 → 153.7 µs
(−22.0%)
- string_views size:4096 str_len:128 null:0.1 mixed:false: 173.3 → 141.7
µs (−18.2%)
- string_views size:4096 str_len:128 null:0.1 mixed:true: 184.0 → 142.8
µs (−22.4%)
- string_views size:8192 str_len:10 null:0 mixed:false: 302.9 → 150.2 µs
(−50.4%)
- string_views size:8192 str_len:10 null:0 mixed:true: 352.9 → 279.0 µs
(−20.9%)
- string_views size:8192 str_len:10 null:0.1 mixed:false: 285.0 → 154.3
µs (−45.9%)
- string_views size:8192 str_len:10 null:0.1 mixed:true: 334.2 → 266.4
µs (−20.3%)
- string_views size:8192 str_len:64 null:0 mixed:false: 295.6 → 184.4 µs
(−37.6%)
- string_views size:8192 str_len:64 null:0 mixed:true: 371.4 → 290.7 µs
(−21.7%)
- string_views size:8192 str_len:64 null:0.1 mixed:false: 273.7 → 195.1
µs (−28.7%)
- string_views size:8192 str_len:64 null:0.1 mixed:true: 347.0 → 279.6
µs (−19.4%)
- string_views size:8192 str_len:128 null:0 mixed:false: 379.6 → 285.6
µs (−24.8%)
- string_views size:8192 str_len:128 null:0 mixed:true: 397.1 → 317.4 µs
(−20.1%)
- string_views size:8192 str_len:128 null:0.1 mixed:false: 364.1 → 285.1
µs (−21.7%)
- string_views size:8192 str_len:128 null:0.1 mixed:true: 379.3 → 302.3
µs (−20.3%)
- lower_sliced_ascii parent=65536 slice=128 str_len=32: 980.2 → 797.9 ns
(−18.6%)
lower — some non-ASCII string_views (mostly noise)
- size:4096 str_len:10 null:0 mixed:false: 374.5 → 362.2 µs (−3.3%)
- size:4096 str_len:10 null:0 mixed:true: 374.6 → 380.5 µs (+1.6%)
- size:4096 str_len:10 null:0.1 mixed:false: 340.8 → 356.5 µs (+4.6%)
- size:4096 str_len:10 null:0.1 mixed:true: 344.0 → 352.5 µs (+2.5%)
- size:4096 str_len:64 null:0 mixed:false: 377.5 → 373.5 µs (−1.1%)
- size:4096 str_len:64 null:0 mixed:true: 380.6 → 375.0 µs (−1.5%)
- size:4096 str_len:64 null:0.1 mixed:false: 330.7 → 341.8 µs (+3.4%)
- size:4096 str_len:64 null:0.1 mixed:true: 341.8 → 354.2 µs (+3.6%)
- size:4096 str_len:128 null:0 mixed:false: 371.8 → 356.2 µs (−4.2%)
- size:4096 str_len:128 null:0 mixed:true: 378.9 → 386.0 µs (+1.9%)
- size:4096 str_len:128 null:0.1 mixed:false: 350.5 → 350.3 µs (−0.1%)
- size:4096 str_len:128 null:0.1 mixed:true: 351.0 → 337.9 µs (−3.7%)
- size:8192 str_len:10 null:0 mixed:false: 740.0 → 757.2 µs (+2.3%)
- size:8192 str_len:10 null:0 mixed:true: 781.3 → 750.2 µs (−4.0%)
- size:8192 str_len:10 null:0.1 mixed:false: 693.7 → 693.7 µs (0.0%)
- size:8192 str_len:10 null:0.1 mixed:true: 681.5 → 705.2 µs (+3.5%)
- size:8192 str_len:64 null:0 mixed:false: 755.5 → 768.6 µs (+1.7%)
- size:8192 str_len:64 null:0 mixed:true: 759.6 → 754.3 µs (−0.7%)
- size:8192 str_len:64 null:0.1 mixed:false: 711.5 → 667.8 µs (−6.1%)
- size:8192 str_len:64 null:0.1 mixed:true: 682.1 → 688.2 µs (+0.9%)
- size:8192 str_len:128 null:0 mixed:false: 771.5 → 765.9 µs (−0.7%)
- size:8192 str_len:128 null:0 mixed:true: 747.7 → 792.6 µs (+6.0%)
- size:8192 str_len:128 null:0.1 mixed:false: 687.1 → 701.3 µs (+2.1%)
- size:8192 str_len:128 null:0.1 mixed:true: 679.2 → 696.8 µs (+2.6%)
lower — first/middle non-ASCII (flat)
- lower_the_first_value_is_nonascii: 1024: 42.1 → 42.4 µs (+0.7%)
- lower_the_first_value_is_nonascii: 4096: 173.9 → 173.3 µs (−0.3%)
- lower_the_first_value_is_nonascii: 8192: 350.8 → 349.3 µs (−0.4%)
- lower_the_middle_value_is_nonascii: 1024: 42.9 → 42.8 µs (−0.2%)
- lower_the_middle_value_is_nonascii: 4096: 175.1 → 176.3 µs (+0.7%)
- lower_the_middle_value_is_nonascii: 8192: 353.6 → 354.6 µs (+0.3%)
## What changes are included in this PR?
* Implement optimizations
* Share StringViewArray buffer size constants with the bulk-NULL
builders
## Are these changes tested?
Covered by existing tests.
## Are there any user-facing changes?
No.
1 parent d4fb7ef commit ae796ab
4 files changed
Lines changed: 503 additions & 70 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
19 | 19 | | |
20 | 20 | | |
21 | 21 | | |
22 | | - | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
23 | 26 | | |
24 | 27 | | |
25 | 28 | | |
| |||
323 | 326 | | |
324 | 327 | | |
325 | 328 | | |
326 | | - | |
| 329 | + | |
327 | 330 | | |
328 | 331 | | |
329 | 332 | | |
330 | | - | |
| 333 | + | |
| 334 | + | |
| 335 | + | |
| 336 | + | |
| 337 | + | |
| 338 | + | |
| 339 | + | |
| 340 | + | |
| 341 | + | |
| 342 | + | |
331 | 343 | | |
332 | 344 | | |
333 | | - | |
334 | | - | |
335 | | - | |
| 345 | + | |
| 346 | + | |
| 347 | + | |
336 | 348 | | |
337 | | - | |
338 | | - | |
339 | | - | |
340 | | - | |
| 349 | + | |
341 | 350 | | |
342 | 351 | | |
343 | | - | |
344 | | - | |
| 352 | + | |
| 353 | + | |
345 | 354 | | |
346 | | - | |
347 | | - | |
348 | | - | |
349 | | - | |
| 355 | + | |
| 356 | + | |
| 357 | + | |
350 | 358 | | |
351 | 359 | | |
| 360 | + | |
| 361 | + | |
| 362 | + | |
| 363 | + | |
| 364 | + | |
352 | 365 | | |
353 | 366 | | |
354 | 367 | | |
| |||
361 | 374 | | |
362 | 375 | | |
363 | 376 | | |
364 | | - | |
| 377 | + | |
365 | 378 | | |
366 | 379 | | |
367 | 380 | | |
368 | 381 | | |
369 | 382 | | |
370 | 383 | | |
371 | | - | |
| 384 | + | |
372 | 385 | | |
373 | 386 | | |
374 | 387 | | |
| |||
378 | 391 | | |
379 | 392 | | |
380 | 393 | | |
381 | | - | |
| 394 | + | |
382 | 395 | | |
383 | 396 | | |
384 | 397 | | |
385 | | - | |
| 398 | + | |
386 | 399 | | |
387 | 400 | | |
388 | 401 | | |
389 | | - | |
| 402 | + | |
390 | 403 | | |
391 | 404 | | |
392 | 405 | | |
393 | 406 | | |
394 | 407 | | |
395 | 408 | | |
396 | 409 | | |
397 | | - | |
398 | | - | |
399 | | - | |
400 | | - | |
401 | | - | |
| 410 | + | |
| 411 | + | |
| 412 | + | |
| 413 | + | |
402 | 414 | | |
403 | 415 | | |
404 | 416 | | |
405 | 417 | | |
406 | | - | |
| 418 | + | |
407 | 419 | | |
408 | 420 | | |
409 | 421 | | |
| |||
423 | 435 | | |
424 | 436 | | |
425 | 437 | | |
426 | | - | |
| 438 | + | |
427 | 439 | | |
428 | 440 | | |
429 | 441 | | |
430 | 442 | | |
431 | 443 | | |
432 | 444 | | |
433 | | - | |
| 445 | + | |
434 | 446 | | |
435 | 447 | | |
436 | 448 | | |
437 | 449 | | |
438 | 450 | | |
| 451 | + | |
| 452 | + | |
| 453 | + | |
| 454 | + | |
| 455 | + | |
| 456 | + | |
| 457 | + | |
| 458 | + | |
| 459 | + | |
| 460 | + | |
| 461 | + | |
| 462 | + | |
| 463 | + | |
| 464 | + | |
| 465 | + | |
| 466 | + | |
| 467 | + | |
| 468 | + | |
| 469 | + | |
| 470 | + | |
| 471 | + | |
| 472 | + | |
| 473 | + | |
| 474 | + | |
| 475 | + | |
| 476 | + | |
| 477 | + | |
| 478 | + | |
| 479 | + | |
| 480 | + | |
| 481 | + | |
| 482 | + | |
| 483 | + | |
| 484 | + | |
| 485 | + | |
| 486 | + | |
| 487 | + | |
| 488 | + | |
| 489 | + | |
| 490 | + | |
| 491 | + | |
| 492 | + | |
| 493 | + | |
| 494 | + | |
| 495 | + | |
| 496 | + | |
| 497 | + | |
| 498 | + | |
| 499 | + | |
| 500 | + | |
| 501 | + | |
| 502 | + | |
| 503 | + | |
| 504 | + | |
| 505 | + | |
| 506 | + | |
| 507 | + | |
| 508 | + | |
| 509 | + | |
| 510 | + | |
| 511 | + | |
| 512 | + | |
| 513 | + | |
| 514 | + | |
| 515 | + | |
| 516 | + | |
| 517 | + | |
| 518 | + | |
| 519 | + | |
| 520 | + | |
| 521 | + | |
| 522 | + | |
| 523 | + | |
| 524 | + | |
| 525 | + | |
| 526 | + | |
| 527 | + | |
| 528 | + | |
| 529 | + | |
| 530 | + | |
| 531 | + | |
| 532 | + | |
| 533 | + | |
| 534 | + | |
| 535 | + | |
| 536 | + | |
| 537 | + | |
| 538 | + | |
| 539 | + | |
| 540 | + | |
| 541 | + | |
| 542 | + | |
| 543 | + | |
| 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 | + | |
439 | 577 | | |
440 | 578 | | |
441 | | - | |
442 | | - | |
443 | | - | |
444 | | - | |
445 | | - | |
446 | | - | |
447 | | - | |
448 | | - | |
449 | | - | |
450 | | - | |
| 579 | + | |
| 580 | + | |
| 581 | + | |
| 582 | + | |
| 583 | + | |
| 584 | + | |
451 | 585 | | |
452 | 586 | | |
453 | 587 | | |
454 | 588 | | |
455 | 589 | | |
456 | | - | |
457 | | - | |
458 | | - | |
459 | | - | |
460 | | - | |
461 | | - | |
462 | | - | |
| 590 | + | |
| 591 | + | |
| 592 | + | |
| 593 | + | |
| 594 | + | |
| 595 | + | |
463 | 596 | | |
464 | 597 | | |
465 | 598 | | |
| |||
468 | 601 | | |
469 | 602 | | |
470 | 603 | | |
471 | | - | |
| 604 | + | |
472 | 605 | | |
473 | 606 | | |
474 | 607 | | |
| |||
0 commit comments