Commit 99a6300
ARROW-11108: [Rust] Fixed performance issue in mutableBuffer.
This PR refactors `MutableBuffer::extend_from_slice` to remove the need to use `to_byte_slice` on every call, thereby removing its level of indirection, that does not allow the compiler to optimize out some code.
This is the second performance improvement originally presented in #8796 and, together with #9027 , brings the performance of "MutableBuffer" to the same level as `Vec<u8>`, in particular to building buffers on the fly.
Basically, when converting to a byte slice `&[u8]`, the compiler loses the type size information, and thus needs to perform extra checks and can't just optimize out the code.
This PR adopts the same API as `Vec<T>::extend_from_slice`, but since our buffers are in `u8` (i.e. a la `Vec<u8>`), I made the signature
```
pub fn extend_from_slice<T: ToByteSlice>(&mut self, items: &[T])
pub fn push<T: ToByteSlice>(&mut self, item: &T)
```
i.e. it consumes something that can be converted to a byte slice, but internally makes the conversion to bytes (as `to_byte_slice` was doing).
Credits for the root cause analysis that lead to this PR go to @Dandandan, [originally fielded here](#9016 (comment)).
> [...] current conversion to a byte slice may add some overhead? - @Dandandan
Benches (against master, so, both this PR and #9044 ):
```
Switched to branch 'perf_buffer'
Your branch and 'origin/perf_buffer' have diverged,
and have 6 and 1 different commits each, respectively.
(use "git pull" to merge the remote branch into yours)
Compiling arrow v3.0.0-SNAPSHOT (/Users/jorgecarleitao/projects/arrow/rust/arrow)
Finished bench [optimized] target(s) in 1m 00s
Running /Users/jorgecarleitao/projects/arrow/rust/target/release/deps/buffer_create-915da5f1abaf0471
Gnuplot not found, using plotters backend
mutable time: [463.11 us 463.57 us 464.07 us]
change: [-19.508% -18.571% -17.526%] (p = 0.00 < 0.05)
Performance has improved.
Found 10 outliers among 100 measurements (10.00%)
1 (1.00%) high mild
9 (9.00%) high severe
mutable prepared time: [527.84 us 528.46 us 529.14 us]
change: [-13.356% -12.522% -11.790%] (p = 0.00 < 0.05)
Performance has improved.
Found 12 outliers among 100 measurements (12.00%)
5 (5.00%) high mild
7 (7.00%) high severe
Benchmarking from_slice: Warming up for 3.0000 s
Warning: Unable to complete 100 samples in 5.0s. You may wish to increase target time to 6.1s, enable flat sampling, or reduce sample count to 60.
from_slice time: [1.1968 ms 1.1979 ms 1.1991 ms]
change: [-6.8697% -6.2029% -5.5812%] (p = 0.00 < 0.05)
Performance has improved.
Found 10 outliers among 100 measurements (10.00%)
3 (3.00%) high mild
7 (7.00%) high severe
from_slice prepared time: [917.49 us 918.89 us 920.60 us]
change: [-6.5111% -5.9102% -5.3038%] (p = 0.00 < 0.05)
Performance has improved.
Found 10 outliers among 100 measurements (10.00%)
4 (4.00%) high mild
6 (6.00%) high severe
```
Closes #9076 from jorgecarleitao/perf_buffer
Authored-by: Jorge C. Leitao <jorgecarleitao@gmail.com>
Signed-off-by: Jorge C. Leitao <jorgecarleitao@gmail.com>1 parent aeeeca0 commit 99a6300
File tree
38 files changed
+492
-552
lines changed- rust
- arrow
- benches
- src
- array
- equal
- transform
- compute
- kernels
- json
- util
- parquet/src/arrow
38 files changed
+492
-552
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
33 | 33 | | |
34 | 34 | | |
35 | 35 | | |
36 | | - | |
37 | | - | |
| 36 | + | |
38 | 37 | | |
39 | 38 | | |
40 | 39 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
27 | 27 | | |
28 | 28 | | |
29 | 29 | | |
| 30 | + | |
30 | 31 | | |
31 | | - | |
32 | 32 | | |
33 | 33 | | |
34 | 34 | | |
| |||
110 | 110 | | |
111 | 111 | | |
112 | 112 | | |
113 | | - | |
114 | | - | |
| 113 | + | |
| 114 | + | |
115 | 115 | | |
116 | 116 | | |
117 | 117 | | |
| |||
245 | 245 | | |
246 | 246 | | |
247 | 247 | | |
248 | | - | |
249 | | - | |
| 248 | + | |
| 249 | + | |
250 | 250 | | |
251 | 251 | | |
252 | 252 | | |
| |||
368 | 368 | | |
369 | 369 | | |
370 | 370 | | |
371 | | - | |
| 371 | + | |
372 | 372 | | |
373 | 373 | | |
374 | 374 | | |
| |||
641 | 641 | | |
642 | 642 | | |
643 | 643 | | |
644 | | - | |
645 | | - | |
| 644 | + | |
| 645 | + | |
646 | 646 | | |
647 | 647 | | |
648 | 648 | | |
| |||
664 | 664 | | |
665 | 665 | | |
666 | 666 | | |
667 | | - | |
668 | | - | |
| 667 | + | |
| 668 | + | |
669 | 669 | | |
670 | 670 | | |
671 | 671 | | |
| |||
688 | 688 | | |
689 | 689 | | |
690 | 690 | | |
691 | | - | |
692 | | - | |
| 691 | + | |
| 692 | + | |
693 | 693 | | |
694 | 694 | | |
695 | 695 | | |
| |||
711 | 711 | | |
712 | 712 | | |
713 | 713 | | |
714 | | - | |
715 | | - | |
| 714 | + | |
| 715 | + | |
716 | 716 | | |
717 | 717 | | |
718 | 718 | | |
| |||
739 | 739 | | |
740 | 740 | | |
741 | 741 | | |
742 | | - | |
743 | | - | |
| 742 | + | |
| 743 | + | |
744 | 744 | | |
745 | 745 | | |
746 | 746 | | |
747 | 747 | | |
748 | 748 | | |
749 | | - | |
| 749 | + | |
750 | 750 | | |
751 | 751 | | |
752 | 752 | | |
| |||
778 | 778 | | |
779 | 779 | | |
780 | 780 | | |
781 | | - | |
782 | | - | |
| 781 | + | |
| 782 | + | |
783 | 783 | | |
784 | 784 | | |
785 | 785 | | |
786 | 786 | | |
787 | 787 | | |
788 | | - | |
| 788 | + | |
789 | 789 | | |
790 | 790 | | |
791 | 791 | | |
| |||
838 | 838 | | |
839 | 839 | | |
840 | 840 | | |
841 | | - | |
| 841 | + | |
842 | 842 | | |
843 | 843 | | |
844 | 844 | | |
845 | 845 | | |
846 | 846 | | |
847 | | - | |
| 847 | + | |
848 | 848 | | |
849 | 849 | | |
850 | 850 | | |
| |||
860 | 860 | | |
861 | 861 | | |
862 | 862 | | |
863 | | - | |
| 863 | + | |
864 | 864 | | |
865 | 865 | | |
866 | 866 | | |
867 | 867 | | |
868 | 868 | | |
869 | 869 | | |
870 | | - | |
| 870 | + | |
871 | 871 | | |
872 | 872 | | |
873 | 873 | | |
| |||
934 | 934 | | |
935 | 935 | | |
936 | 936 | | |
937 | | - | |
| 937 | + | |
938 | 938 | | |
939 | 939 | | |
940 | 940 | | |
| |||
957 | 957 | | |
958 | 958 | | |
959 | 959 | | |
960 | | - | |
961 | | - | |
| 960 | + | |
| 961 | + | |
962 | 962 | | |
963 | 963 | | |
964 | 964 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
163 | 163 | | |
164 | 164 | | |
165 | 165 | | |
166 | | - | |
167 | | - | |
| 166 | + | |
| 167 | + | |
168 | 168 | | |
169 | 169 | | |
170 | 170 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
298 | 298 | | |
299 | 299 | | |
300 | 300 | | |
301 | | - | |
302 | | - | |
303 | | - | |
304 | | - | |
305 | | - | |
| 301 | + | |
306 | 302 | | |
307 | 303 | | |
308 | 304 | | |
| |||
313 | 309 | | |
314 | 310 | | |
315 | 311 | | |
316 | | - | |
| 312 | + | |
317 | 313 | | |
318 | 314 | | |
319 | 315 | | |
320 | 316 | | |
321 | | - | |
| 317 | + | |
322 | 318 | | |
323 | 319 | | |
324 | 320 | | |
| |||
383 | 379 | | |
384 | 380 | | |
385 | 381 | | |
386 | | - | |
| 382 | + | |
387 | 383 | | |
388 | 384 | | |
389 | 385 | | |
390 | 386 | | |
391 | | - | |
| 387 | + | |
392 | 388 | | |
393 | 389 | | |
394 | 390 | | |
| |||
453 | 449 | | |
454 | 450 | | |
455 | 451 | | |
456 | | - | |
| 452 | + | |
457 | 453 | | |
458 | 454 | | |
459 | 455 | | |
| |||
522 | 518 | | |
523 | 519 | | |
524 | 520 | | |
525 | | - | |
| 521 | + | |
526 | 522 | | |
527 | 523 | | |
528 | 524 | | |
| |||
542 | 538 | | |
543 | 539 | | |
544 | 540 | | |
545 | | - | |
546 | | - | |
547 | | - | |
| 541 | + | |
548 | 542 | | |
549 | 543 | | |
550 | 544 | | |
551 | 545 | | |
552 | | - | |
553 | | - | |
| 546 | + | |
554 | 547 | | |
555 | 548 | | |
556 | 549 | | |
| |||
607 | 600 | | |
608 | 601 | | |
609 | 602 | | |
610 | | - | |
611 | | - | |
612 | | - | |
| 603 | + | |
613 | 604 | | |
614 | 605 | | |
615 | 606 | | |
616 | 607 | | |
617 | | - | |
618 | | - | |
| 608 | + | |
619 | 609 | | |
620 | 610 | | |
621 | 611 | | |
| |||
674 | 664 | | |
675 | 665 | | |
676 | 666 | | |
677 | | - | |
678 | | - | |
679 | | - | |
| 667 | + | |
680 | 668 | | |
681 | 669 | | |
682 | 670 | | |
| |||
737 | 725 | | |
738 | 726 | | |
739 | 727 | | |
740 | | - | |
| 728 | + | |
741 | 729 | | |
742 | 730 | | |
743 | 731 | | |
| |||
753 | 741 | | |
754 | 742 | | |
755 | 743 | | |
756 | | - | |
| 744 | + | |
757 | 745 | | |
758 | 746 | | |
759 | 747 | | |
| |||
768 | 756 | | |
769 | 757 | | |
770 | 758 | | |
771 | | - | |
| 759 | + | |
772 | 760 | | |
773 | 761 | | |
774 | | - | |
| 762 | + | |
775 | 763 | | |
776 | 764 | | |
777 | 765 | | |
| |||
782 | 770 | | |
783 | 771 | | |
784 | 772 | | |
785 | | - | |
786 | | - | |
787 | | - | |
788 | | - | |
789 | | - | |
790 | | - | |
791 | | - | |
792 | | - | |
793 | | - | |
794 | | - | |
795 | | - | |
796 | | - | |
797 | | - | |
798 | | - | |
799 | | - | |
800 | | - | |
801 | | - | |
802 | | - | |
803 | | - | |
804 | | - | |
805 | | - | |
806 | | - | |
807 | | - | |
808 | | - | |
809 | | - | |
810 | | - | |
811 | | - | |
812 | | - | |
813 | | - | |
814 | | - | |
815 | | - | |
816 | 773 | | |
0 commit comments