Commit 111456a
committed
Avoid per-byte loop in cstring{,Utf8} builders
Copy chunks of the input to the output buffer with, up to the shorter
of the available buffer space and the "null-free" portion of the remaining
string. Actually "null-free" here means not containing any denormalised
two-byte encodings starting with 0xC0 (so possibly also other ASCII
bytes if the UTF-8 encoding is oddball).
This substantially improves performance, with just one "15%" increase
that looks like a spurious measurement error (perhaps code layout
difference artefact).
UTF-8 String (12B): OK
16.7 ns ± 1.3 ns, 60% less than baseline
UTF-8 String (64B, one null): OK
22.6 ns ± 1.3 ns, 87% less than baseline
UTF-8 String (64B, one null, no shared work): OK
30.1 ns ± 2.6 ns, 83% less than baseline
UTF-8 String (64B, half nulls): OK
92.6 ns ± 5.3 ns, 49% less than baseline
UTF-8 String (64B, all nulls): OK
76.3 ns ± 4.5 ns, 57% less than baseline
UTF-8 String (64B, all nulls, no shared work): OK
82.3 ns ± 5.6 ns, 54% less than baseline
ASCII String (12B): OK
6.50 ns ± 326 ps, 76% less than baseline
ASCII String (64B): OK
8.03 ns ± 334 ps, 94% less than baseline
AsciiLit: OK
8.02 ns ± 648 ps, 94% less than baseline
Utf8Lit: OK
21.8 ns ± 1.3 ns, 88% less than baseline
strLit: OK
8.90 ns ± 788 ps, 94% less than baseline
stringUtf8: OK
22.4 ns ± 1.3 ns, 87% less than baseline
strLitInline: OK
8.26 ns ± 676 ps, 94% less than baseline
utf8LitInline: OK
23.2 ns ± 1.3 ns, 87% less than baseline
foldMap byteStringInsert (10000): OK
46.0 μs ± 4.0 μs, 15% less than baseline
--> lazyByteStringHex (10000): OK
--> 4.74 μs ± 337 ns, 15% more than baseline
foldMap integerDec (small) (10000): OK
205 μs ± 12 μs, 9% less than baseline
char8 (10000): OK
2.58 μs ± 234 ns, 30% less than baseline
foldMap (left-assoc) (10000): OK
73.2 μs ± 2.9 μs, 54% less than baseline
foldMap (right-assoc) (10000): OK
43.0 μs ± 4.2 μs, 65% less than baseline
foldMap [manually fused, left-assoc] (10000): OK
81.4 μs ± 5.3 μs, 48% less than baseline
foldMap [manually fused, right-assoc] (10000): OK
47.3 μs ± 785 ns, 61% less than baseline1 parent 188512c commit 111456a
File tree
4 files changed
+157
-55
lines changed- Data/ByteString/Builder
- bench
- tests/builder/Data/ByteString/Builder/Prim
4 files changed
+157
-55
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | | - | |
2 | | - | |
| 1 | + | |
3 | 2 | | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
4 | 6 | | |
5 | 7 | | |
6 | 8 | | |
| |||
87 | 89 | | |
88 | 90 | | |
89 | 91 | | |
| 92 | + | |
| 93 | + | |
90 | 94 | | |
91 | 95 | | |
92 | 96 | | |
| |||
816 | 820 | | |
817 | 821 | | |
818 | 822 | | |
| 823 | + | |
819 | 824 | | |
820 | 825 | | |
821 | 826 | | |
| |||
839 | 844 | | |
840 | 845 | | |
841 | 846 | | |
| 847 | + | |
| 848 | + | |
| 849 | + | |
| 850 | + | |
| 851 | + | |
| 852 | + | |
| 853 | + | |
| 854 | + | |
| 855 | + | |
| 856 | + | |
| 857 | + | |
| 858 | + | |
| 859 | + | |
| 860 | + | |
| 861 | + | |
| 862 | + | |
| 863 | + | |
| 864 | + | |
| 865 | + | |
842 | 866 | | |
843 | 867 | | |
844 | 868 | | |
| |||
858 | 882 | | |
859 | 883 | | |
860 | 884 | | |
| 885 | + | |
861 | 886 | | |
862 | 887 | | |
863 | 888 | | |
| |||
949 | 974 | | |
950 | 975 | | |
951 | 976 | | |
| 977 | + | |
| 978 | + | |
| 979 | + | |
| 980 | + | |
| 981 | + | |
| 982 | + | |
| 983 | + | |
| 984 | + | |
| 985 | + | |
| 986 | + | |
| 987 | + | |
| 988 | + | |
| 989 | + | |
| 990 | + | |
| 991 | + | |
| 992 | + | |
| 993 | + | |
| 994 | + | |
| 995 | + | |
| 996 | + | |
| 997 | + | |
| 998 | + | |
| 999 | + | |
| 1000 | + | |
| 1001 | + | |
| 1002 | + | |
| 1003 | + | |
| 1004 | + | |
| 1005 | + | |
| 1006 | + | |
| 1007 | + | |
| 1008 | + | |
| 1009 | + | |
| 1010 | + | |
| 1011 | + | |
| 1012 | + | |
| 1013 | + | |
| 1014 | + | |
| 1015 | + | |
| 1016 | + | |
| 1017 | + | |
| 1018 | + | |
| 1019 | + | |
| 1020 | + | |
| 1021 | + | |
| 1022 | + | |
| 1023 | + | |
| 1024 | + | |
| 1025 | + | |
| 1026 | + | |
| 1027 | + | |
| 1028 | + | |
| 1029 | + | |
| 1030 | + | |
| 1031 | + | |
| 1032 | + | |
| 1033 | + | |
| 1034 | + | |
| 1035 | + | |
| 1036 | + | |
| 1037 | + | |
| 1038 | + | |
| 1039 | + | |
| 1040 | + | |
| 1041 | + | |
| 1042 | + | |
| 1043 | + | |
| 1044 | + | |
| 1045 | + | |
| 1046 | + | |
| 1047 | + | |
| 1048 | + | |
| 1049 | + | |
| 1050 | + | |
| 1051 | + | |
| 1052 | + | |
| 1053 | + | |
| 1054 | + | |
| 1055 | + | |
| 1056 | + | |
| 1057 | + | |
952 | 1058 | | |
953 | 1059 | | |
954 | 1060 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
1 | 2 | | |
2 | 3 | | |
| 4 | + | |
| 5 | + | |
3 | 6 | | |
4 | 7 | | |
5 | 8 | | |
| |||
464 | 467 | | |
465 | 468 | | |
466 | 469 | | |
467 | | - | |
468 | 470 | | |
469 | | - | |
470 | 471 | | |
471 | 472 | | |
472 | 473 | | |
| |||
658 | 659 | | |
659 | 660 | | |
660 | 661 | | |
661 | | - | |
662 | | - | |
663 | | - | |
664 | | - | |
665 | | - | |
666 | | - | |
| 662 | + | |
| 663 | + | |
667 | 664 | | |
668 | 665 | | |
669 | 666 | | |
670 | | - | |
671 | | - | |
672 | | - | |
673 | | - | |
674 | | - | |
675 | | - | |
676 | | - | |
677 | | - | |
678 | | - | |
679 | | - | |
680 | | - | |
681 | | - | |
682 | | - | |
683 | | - | |
684 | | - | |
| 667 | + | |
| 668 | + | |
685 | 669 | | |
686 | | - | |
687 | | - | |
| 670 | + | |
| 671 | + | |
| 672 | + | |
688 | 673 | | |
689 | 674 | | |
690 | 675 | | |
691 | | - | |
692 | | - | |
693 | | - | |
694 | | - | |
695 | | - | |
696 | | - | |
697 | | - | |
698 | | - | |
699 | | - | |
700 | | - | |
701 | | - | |
702 | | - | |
703 | | - | |
704 | | - | |
705 | | - | |
706 | | - | |
707 | | - | |
708 | | - | |
709 | | - | |
710 | | - | |
711 | | - | |
712 | | - | |
713 | | - | |
| 676 | + | |
| 677 | + | |
| 678 | + | |
| 679 | + | |
| 680 | + | |
| 681 | + | |
| 682 | + | |
| 683 | + | |
| 684 | + | |
| 685 | + | |
| 686 | + | |
| 687 | + | |
| 688 | + | |
| 689 | + | |
| 690 | + | |
| 691 | + | |
714 | 692 | | |
715 | 693 | | |
716 | 694 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
327 | 327 | | |
328 | 328 | | |
329 | 329 | | |
| 330 | + | |
| 331 | + | |
| 332 | + | |
| 333 | + | |
| 334 | + | |
| 335 | + | |
330 | 336 | | |
331 | 337 | | |
332 | 338 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
14 | 14 | | |
15 | 15 | | |
16 | 16 | | |
| 17 | + | |
17 | 18 | | |
18 | 19 | | |
19 | 20 | | |
| |||
22 | 23 | | |
23 | 24 | | |
24 | 25 | | |
25 | | - | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
26 | 33 | | |
27 | 34 | | |
28 | 35 | | |
29 | 36 | | |
30 | 37 | | |
31 | 38 | | |
32 | | - | |
33 | | - | |
34 | | - | |
35 | | - | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
36 | 48 | | |
37 | 49 | | |
38 | 50 | | |
| |||
0 commit comments