Commit 3de9411
authored
base(nc|32|64): Optimize performances reduction memset (#9632)
* perf(base32): optimize read buffer allocation in fast encode/decode
Refactor buffer creation from zero-initialized vectors to pre-allocated Vec with_capacity,
using unsafe set_len to avoid unnecessary zeroing, improving performance without affecting
correctness, as only initialized bytes from Read::read are accessed.
* refactor: use MaybeUninit for safer buffer handling in base32 encode/decode
Replaced manual unsafe `set_len` calls and direct reads into uninitialized vectors with `MaybeUninit::slice_assume_init_mut` to prevent potential memory safety issues and improve code reliability in `fast_encode` and `fast_decode` modules. Added buffer clearing to ensure proper reuse.
* refactor(base32): replace MaybeUninit::slice_assume_init_mut with slice::from_raw_parts_mut
Replace unsafe usage of `MaybeUninit::slice_assume_init_mut` with `slice::from_raw_parts_mut` in the fast_encode and fast_decode modules for reading data into the spare capacity of buffers. This change maintains safety guarantees through updated comments while potentially improving code clarity and performance by avoiding MaybeUninit initialization assumptions. The modification ensures the buffer's uninitialized tail is correctly handled as raw bytes during I/O operations.
* refactor(base32): reorder std imports in base_common.rs for consistency
Moved the `slice` import from after `collections::VecDeque` to after `num::NonZeroUsize` to better align with the module's import grouping style.
* refactor(base32): remove unsafe buffer handling in encode/decode
Replace unsafe spare_capacity_mut and from_raw_parts_mut usage with safe Vec initialization and direct read calls in fast_encode and fast_decode. This eliminates potential safety risks while preserving buffer functionality.
* perf(base32): optimize input handling by switching to BufRead for efficient buffering
Switch from unbuffered Read to BufRead in get_input, handle_input, and fast_encode_stream functions. This reduces syscalls by leveraging buffered reads, improving performance for base32 encoding/decoding operations. Refactor fast_encode_stream to use fill_buf() and manage leftover buffers more efficiently.1 parent 9212ce2 commit 3de9411
1 file changed
+77
-39
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
8 | 8 | | |
9 | 9 | | |
10 | 10 | | |
11 | | - | |
| 11 | + | |
12 | 12 | | |
13 | 13 | | |
14 | 14 | | |
| |||
146 | 146 | | |
147 | 147 | | |
148 | 148 | | |
149 | | - | |
| 149 | + | |
150 | 150 | | |
151 | 151 | | |
152 | 152 | | |
153 | 153 | | |
154 | | - | |
| 154 | + | |
| 155 | + | |
| 156 | + | |
| 157 | + | |
155 | 158 | | |
156 | 159 | | |
157 | 160 | | |
158 | | - | |
| 161 | + | |
| 162 | + | |
| 163 | + | |
| 164 | + | |
159 | 165 | | |
160 | 166 | | |
161 | 167 | | |
162 | | - | |
| 168 | + | |
163 | 169 | | |
164 | 170 | | |
165 | 171 | | |
| |||
292 | 298 | | |
293 | 299 | | |
294 | 300 | | |
295 | | - | |
| 301 | + | |
296 | 302 | | |
297 | 303 | | |
298 | 304 | | |
299 | | - | |
| 305 | + | |
300 | 306 | | |
301 | 307 | | |
302 | 308 | | |
| |||
519 | 525 | | |
520 | 526 | | |
521 | 527 | | |
522 | | - | |
| 528 | + | |
523 | 529 | | |
524 | 530 | | |
525 | 531 | | |
| |||
544 | 550 | | |
545 | 551 | | |
546 | 552 | | |
547 | | - | |
548 | 553 | | |
549 | | - | |
550 | | - | |
| 554 | + | |
551 | 555 | | |
552 | 556 | | |
553 | | - | |
554 | | - | |
| 557 | + | |
| 558 | + | |
555 | 559 | | |
556 | | - | |
| 560 | + | |
557 | 561 | | |
558 | 562 | | |
559 | 563 | | |
560 | | - | |
| 564 | + | |
561 | 565 | | |
562 | | - | |
563 | | - | |
564 | | - | |
| 566 | + | |
| 567 | + | |
| 568 | + | |
| 569 | + | |
| 570 | + | |
| 571 | + | |
| 572 | + | |
565 | 573 | | |
566 | 574 | | |
567 | | - | |
| 575 | + | |
| 576 | + | |
| 577 | + | |
| 578 | + | |
| 579 | + | |
| 580 | + | |
| 581 | + | |
568 | 582 | | |
| 583 | + | |
| 584 | + | |
| 585 | + | |
569 | 586 | | |
570 | 587 | | |
| 588 | + | |
571 | 589 | | |
572 | | - | |
573 | | - | |
| 590 | + | |
| 591 | + | |
| 592 | + | |
574 | 593 | | |
575 | | - | |
576 | | - | |
577 | | - | |
578 | | - | |
579 | | - | |
580 | | - | |
581 | | - | |
| 594 | + | |
| 595 | + | |
| 596 | + | |
| 597 | + | |
| 598 | + | |
| 599 | + | |
| 600 | + | |
| 601 | + | |
| 602 | + | |
| 603 | + | |
| 604 | + | |
| 605 | + | |
| 606 | + | |
| 607 | + | |
| 608 | + | |
| 609 | + | |
| 610 | + | |
| 611 | + | |
| 612 | + | |
| 613 | + | |
| 614 | + | |
582 | 615 | | |
| 616 | + | |
| 617 | + | |
| 618 | + | |
| 619 | + | |
| 620 | + | |
583 | 621 | | |
584 | 622 | | |
585 | 623 | | |
586 | 624 | | |
587 | | - | |
| 625 | + | |
588 | 626 | | |
589 | 627 | | |
590 | 628 | | |
| |||
599 | 637 | | |
600 | 638 | | |
601 | 639 | | |
602 | | - | |
603 | | - | |
| 640 | + | |
604 | 641 | | |
605 | 642 | | |
606 | 643 | | |
| |||
630 | 667 | | |
631 | 668 | | |
632 | 669 | | |
633 | | - | |
634 | 670 | | |
635 | 671 | | |
636 | 672 | | |
| |||
764 | 800 | | |
765 | 801 | | |
766 | 802 | | |
767 | | - | |
| 803 | + | |
768 | 804 | | |
769 | 805 | | |
770 | 806 | | |
| |||
783 | 819 | | |
784 | 820 | | |
785 | 821 | | |
786 | | - | |
787 | 822 | | |
788 | 823 | | |
789 | | - | |
790 | | - | |
| 824 | + | |
| 825 | + | |
791 | 826 | | |
792 | | - | |
| 827 | + | |
| 828 | + | |
793 | 829 | | |
794 | 830 | | |
795 | 831 | | |
796 | | - | |
| 832 | + | |
797 | 833 | | |
798 | 834 | | |
799 | 835 | | |
| |||
845 | 881 | | |
846 | 882 | | |
847 | 883 | | |
| 884 | + | |
| 885 | + | |
848 | 886 | | |
849 | 887 | | |
850 | 888 | | |
| |||
902 | 940 | | |
903 | 941 | | |
904 | 942 | | |
905 | | - | |
| 943 | + | |
906 | 944 | | |
907 | 945 | | |
908 | 946 | | |
| |||
0 commit comments