Commit 1d131ff
authored
[libc++] Optimize most of the __tree search algorithms (#155245)
This patch introduces a new comparator, namely `__lazy_synth_three_way`,
which tries to provide an efficient three way comparator for known types
and falls back to using the provided comparator if it doesn't know how
to do that. Currently, an efficient three way comparison is only
provided when using one of the `less` comparions object from the
standard library and `std::string`. This will be extended in future
patches.
```
------------------------------------------------------------------------------------------------------------------------------
Benchmark old new
------------------------------------------------------------------------------------------------------------------------------
std::map<std::string, int>::ctor(const&)/0 12.6 ns 12.6 ns
std::map<std::string, int>::ctor(const&)/32 858 ns 837 ns
std::map<std::string, int>::ctor(const&)/1024 46700 ns 46739 ns
std::map<std::string, int>::ctor(const&)/8192 458100 ns 449806 ns
std::map<std::string, int>::ctor(iterator, iterator) (unsorted sequence)/0 12.8 ns 12.7 ns
std::map<std::string, int>::ctor(iterator, iterator) (unsorted sequence)/32 1286 ns 1266 ns
std::map<std::string, int>::ctor(iterator, iterator) (unsorted sequence)/1024 93812 ns 84686 ns
std::map<std::string, int>::ctor(iterator, iterator) (unsorted sequence)/8192 1480346 ns 1385924 ns
std::map<std::string, int>::ctor(iterator, iterator) (sorted sequence)/0 12.9 ns 12.8 ns
std::map<std::string, int>::ctor(iterator, iterator) (sorted sequence)/32 1044 ns 1055 ns
std::map<std::string, int>::ctor(iterator, iterator) (sorted sequence)/1024 63071 ns 62861 ns
std::map<std::string, int>::ctor(iterator, iterator) (sorted sequence)/8192 595046 ns 590223 ns
std::map<std::string, int>::operator=(const&) (into cleared Container)/0 13.6 ns 13.6 ns
std::map<std::string, int>::operator=(const&) (into cleared Container)/32 880 ns 911 ns
std::map<std::string, int>::operator=(const&) (into cleared Container)/1024 48627 ns 47808 ns
std::map<std::string, int>::operator=(const&) (into cleared Container)/8192 458552 ns 454497 ns
std::map<std::string, int>::operator=(const&) (into partially populated Container)/0 13.8 ns 13.6 ns
std::map<std::string, int>::operator=(const&) (into partially populated Container)/32 864 ns 851 ns
std::map<std::string, int>::operator=(const&) (into partially populated Container)/1024 49483 ns 49555 ns
std::map<std::string, int>::operator=(const&) (into partially populated Container)/8192 456977 ns 457894 ns
std::map<std::string, int>::operator=(const&) (into populated Container)/0 1.31 ns 1.31 ns
std::map<std::string, int>::operator=(const&) (into populated Container)/32 425 ns 415 ns
std::map<std::string, int>::operator=(const&) (into populated Container)/1024 14248 ns 14225 ns
std::map<std::string, int>::operator=(const&) (into populated Container)/8192 136684 ns 133696 ns
std::map<std::string, int>::insert(value) (already present)/0 21.5 ns 16.2 ns
std::map<std::string, int>::insert(value) (already present)/32 22.7 ns 25.1 ns
std::map<std::string, int>::insert(value) (already present)/1024 54.5 ns 29.1 ns
std::map<std::string, int>::insert(value) (already present)/8192 78.4 ns 30.4 ns
std::map<std::string, int>::insert(value) (new value)/0 40.9 ns 39.0 ns
std::map<std::string, int>::insert(value) (new value)/32 58.3 ns 47.2 ns
std::map<std::string, int>::insert(value) (new value)/1024 120 ns 71.3 ns
std::map<std::string, int>::insert(value) (new value)/8192 157 ns 129 ns
std::map<std::string, int>::insert(hint, value) (good hint)/0 40.3 ns 40.7 ns
std::map<std::string, int>::insert(hint, value) (good hint)/32 48.0 ns 30.0 ns
std::map<std::string, int>::insert(hint, value) (good hint)/1024 107 ns 63.2 ns
std::map<std::string, int>::insert(hint, value) (good hint)/8192 132 ns 107 ns
std::map<std::string, int>::insert(hint, value) (bad hint)/0 27.0 ns 40.9 ns
std::map<std::string, int>::insert(hint, value) (bad hint)/32 68.3 ns 58.4 ns
std::map<std::string, int>::insert(hint, value) (bad hint)/1024 125 ns 82.0 ns
std::map<std::string, int>::insert(hint, value) (bad hint)/8192 155 ns 150 ns
std::map<std::string, int>::insert(iterator, iterator) (all new keys)/0 404 ns 405 ns
std::map<std::string, int>::insert(iterator, iterator) (all new keys)/32 2004 ns 1805 ns
std::map<std::string, int>::insert(iterator, iterator) (all new keys)/1024 102820 ns 76102 ns
std::map<std::string, int>::insert(iterator, iterator) (all new keys)/8192 1144590 ns 949266 ns
std::map<std::string, int>::insert(iterator, iterator) (half new keys)/0 408 ns 404 ns
std::map<std::string, int>::insert(iterator, iterator) (half new keys)/32 1592 ns 1377 ns
std::map<std::string, int>::insert(iterator, iterator) (half new keys)/1024 74847 ns 53921 ns
std::map<std::string, int>::insert(iterator, iterator) (half new keys)/8192 828505 ns 698716 ns
std::map<std::string, int>::insert(iterator, iterator) (product_iterator from same type)/0 407 ns 407 ns
std::map<std::string, int>::insert(iterator, iterator) (product_iterator from same type)/32 1584 ns 1557 ns
std::map<std::string, int>::insert(iterator, iterator) (product_iterator from same type)/1024 47157 ns 47443 ns
std::map<std::string, int>::insert(iterator, iterator) (product_iterator from same type)/8192 623887 ns 628385 ns
std::map<std::string, int>::insert(iterator, iterator) (product_iterator from zip_view)/0 405 ns 403 ns
std::map<std::string, int>::insert(iterator, iterator) (product_iterator from zip_view)/32 1478 ns 1510 ns
std::map<std::string, int>::insert(iterator, iterator) (product_iterator from zip_view)/1024 47852 ns 47835 ns
std::map<std::string, int>::insert(iterator, iterator) (product_iterator from zip_view)/8192 605311 ns 606951 ns
std::map<std::string, int>::erase(key) (existent)/0 129 ns 94.0 ns
std::map<std::string, int>::erase(key) (existent)/32 110 ns 106 ns
std::map<std::string, int>::erase(key) (existent)/1024 121 ns 128 ns
std::map<std::string, int>::erase(key) (existent)/8192 165 ns 66.9 ns
std::map<std::string, int>::erase(key) (non-existent)/0 0.269 ns 0.257 ns
std::map<std::string, int>::erase(key) (non-existent)/32 21.9 ns 11.3 ns
std::map<std::string, int>::erase(key) (non-existent)/1024 53.5 ns 25.4 ns
std::map<std::string, int>::erase(key) (non-existent)/8192 67.3 ns 31.9 ns
std::map<std::string, int>::erase(iterator)/0 46.3 ns 46.7 ns
std::map<std::string, int>::erase(iterator)/32 44.4 ns 41.8 ns
std::map<std::string, int>::erase(iterator)/1024 43.7 ns 46.4 ns
std::map<std::string, int>::erase(iterator)/8192 45.2 ns 44.1 ns
std::map<std::string, int>::erase(iterator, iterator) (erase half the container)/0 407 ns 407 ns
std::map<std::string, int>::erase(iterator, iterator) (erase half the container)/32 876 ns 906 ns
std::map<std::string, int>::erase(iterator, iterator) (erase half the container)/1024 20880 ns 20444 ns
std::map<std::string, int>::erase(iterator, iterator) (erase half the container)/8192 252881 ns 241583 ns
std::map<std::string, int>::clear()/0 407 ns 408 ns
std::map<std::string, int>::clear()/32 1252 ns 1323 ns
std::map<std::string, int>::clear()/1024 38488 ns 38017 ns
std::map<std::string, int>::clear()/8192 416492 ns 428534 ns
std::map<std::string, int>::find(key) (existent)/0 0.008 ns 0.008 ns
std::map<std::string, int>::find(key) (existent)/32 33.9 ns 15.3 ns
std::map<std::string, int>::find(key) (existent)/1024 43.0 ns 25.5 ns
std::map<std::string, int>::find(key) (existent)/8192 44.6 ns 29.3 ns
std::map<std::string, int>::find(key) (non-existent)/0 0.259 ns 0.257 ns
std::map<std::string, int>::find(key) (non-existent)/32 22.6 ns 11.4 ns
std::map<std::string, int>::find(key) (non-existent)/1024 48.6 ns 25.1 ns
std::map<std::string, int>::find(key) (non-existent)/8192 64.1 ns 31.1 ns
std::map<std::string, int>::count(key) (existent)/0 0.008 ns 0.008 ns
std::map<std::string, int>::count(key) (existent)/32 32.2 ns 17.3 ns
std::map<std::string, int>::count(key) (existent)/1024 42.4 ns 25.3 ns
std::map<std::string, int>::count(key) (existent)/8192 44.4 ns 31.6 ns
std::map<std::string, int>::count(key) (non-existent)/0 0.260 ns 0.259 ns
std::map<std::string, int>::count(key) (non-existent)/32 22.9 ns 11.3 ns
std::map<std::string, int>::count(key) (non-existent)/1024 49.8 ns 25.5 ns
std::map<std::string, int>::count(key) (non-existent)/8192 66.3 ns 31.9 ns
std::map<std::string, int>::contains(key) (existent)/0 0.008 ns 0.008 ns
std::map<std::string, int>::contains(key) (existent)/32 31.4 ns 18.0 ns
std::map<std::string, int>::contains(key) (existent)/1024 44.3 ns 26.5 ns
std::map<std::string, int>::contains(key) (existent)/8192 47.4 ns 30.2 ns
std::map<std::string, int>::contains(key) (non-existent)/0 0.452 ns 0.441 ns
std::map<std::string, int>::contains(key) (non-existent)/32 23.1 ns 11.5 ns
std::map<std::string, int>::contains(key) (non-existent)/1024 46.2 ns 26.3 ns
std::map<std::string, int>::contains(key) (non-existent)/8192 63.4 ns 31.4 ns
std::map<std::string, int>::lower_bound(key) (existent)/0 0.008 ns 0.008 ns
std::map<std::string, int>::lower_bound(key) (existent)/32 17.2 ns 19.0 ns
std::map<std::string, int>::lower_bound(key) (existent)/1024 27.1 ns 26.2 ns
std::map<std::string, int>::lower_bound(key) (existent)/8192 34.0 ns 36.0 ns
std::map<std::string, int>::lower_bound(key) (non-existent)/0 0.259 ns 0.257 ns
std::map<std::string, int>::lower_bound(key) (non-existent)/32 11.6 ns 11.5 ns
std::map<std::string, int>::lower_bound(key) (non-existent)/1024 24.8 ns 25.6 ns
std::map<std::string, int>::lower_bound(key) (non-existent)/8192 31.7 ns 31.6 ns
std::map<std::string, int>::upper_bound(key) (existent)/0 0.008 ns 0.008 ns
std::map<std::string, int>::upper_bound(key) (existent)/32 18.8 ns 19.7 ns
std::map<std::string, int>::upper_bound(key) (existent)/1024 25.3 ns 27.7 ns
std::map<std::string, int>::upper_bound(key) (existent)/8192 30.2 ns 29.9 ns
std::map<std::string, int>::upper_bound(key) (non-existent)/0 0.260 ns 0.259 ns
std::map<std::string, int>::upper_bound(key) (non-existent)/32 11.3 ns 12.0 ns
std::map<std::string, int>::upper_bound(key) (non-existent)/1024 25.6 ns 25.9 ns
std::map<std::string, int>::upper_bound(key) (non-existent)/8192 33.1 ns 34.2 ns
std::map<std::string, int>::equal_range(key) (existent)/0 0.008 ns 0.008 ns
std::map<std::string, int>::equal_range(key) (existent)/32 33.5 ns 15.8 ns
std::map<std::string, int>::equal_range(key) (existent)/1024 43.0 ns 25.1 ns
std::map<std::string, int>::equal_range(key) (existent)/8192 54.1 ns 30.7 ns
std::map<std::string, int>::equal_range(key) (non-existent)/0 0.265 ns 0.259 ns
std::map<std::string, int>::equal_range(key) (non-existent)/32 22.1 ns 12.1 ns
std::map<std::string, int>::equal_range(key) (non-existent)/1024 44.8 ns 24.4 ns
std::map<std::string, int>::equal_range(key) (non-existent)/8192 62.2 ns 40.1 ns
```
Fixes #665771 parent 6a571a1 commit 1d131ff
File tree
14 files changed
+277
-46
lines changed- libcxx
- include
- __utility
- test
- std
- experimental/utilities/meta/meta.detect
- input.output/iostreams.base/fpos/fpos.operations
- support
14 files changed
+277
-46
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
911 | 911 | | |
912 | 912 | | |
913 | 913 | | |
| 914 | + | |
914 | 915 | | |
915 | 916 | | |
916 | 917 | | |
| |||
921 | 922 | | |
922 | 923 | | |
923 | 924 | | |
| 925 | + | |
924 | 926 | | |
925 | 927 | | |
926 | 928 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1156 | 1156 | | |
1157 | 1157 | | |
1158 | 1158 | | |
| 1159 | + | |
| 1160 | + | |
| 1161 | + | |
| 1162 | + | |
| 1163 | + | |
| 1164 | + | |
| 1165 | + | |
1159 | 1166 | | |
1160 | 1167 | | |
1161 | 1168 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
34 | 34 | | |
35 | 35 | | |
36 | 36 | | |
| 37 | + | |
37 | 38 | | |
38 | 39 | | |
39 | 40 | | |
| |||
1749 | 1750 | | |
1750 | 1751 | | |
1751 | 1752 | | |
| 1753 | + | |
| 1754 | + | |
1752 | 1755 | | |
1753 | | - | |
| 1756 | + | |
| 1757 | + | |
| 1758 | + | |
1754 | 1759 | | |
1755 | 1760 | | |
1756 | 1761 | | |
1757 | 1762 | | |
1758 | 1763 | | |
1759 | | - | |
| 1764 | + | |
1760 | 1765 | | |
1761 | 1766 | | |
1762 | 1767 | | |
| |||
2065 | 2070 | | |
2066 | 2071 | | |
2067 | 2072 | | |
| 2073 | + | |
2068 | 2074 | | |
2069 | | - | |
| 2075 | + | |
| 2076 | + | |
2070 | 2077 | | |
2071 | | - | |
| 2078 | + | |
2072 | 2079 | | |
2073 | 2080 | | |
2074 | 2081 | | |
| |||
2082 | 2089 | | |
2083 | 2090 | | |
2084 | 2091 | | |
| 2092 | + | |
2085 | 2093 | | |
2086 | | - | |
| 2094 | + | |
| 2095 | + | |
2087 | 2096 | | |
2088 | 2097 | | |
2089 | | - | |
| 2098 | + | |
2090 | 2099 | | |
2091 | 2100 | | |
2092 | 2101 | | |
| |||
2159 | 2168 | | |
2160 | 2169 | | |
2161 | 2170 | | |
| 2171 | + | |
2162 | 2172 | | |
2163 | | - | |
| 2173 | + | |
| 2174 | + | |
2164 | 2175 | | |
2165 | 2176 | | |
2166 | | - | |
| 2177 | + | |
2167 | 2178 | | |
2168 | 2179 | | |
2169 | 2180 | | |
| |||
2181 | 2192 | | |
2182 | 2193 | | |
2183 | 2194 | | |
| 2195 | + | |
2184 | 2196 | | |
2185 | | - | |
| 2197 | + | |
| 2198 | + | |
2186 | 2199 | | |
2187 | 2200 | | |
2188 | | - | |
| 2201 | + | |
2189 | 2202 | | |
2190 | 2203 | | |
2191 | 2204 | | |
| |||
2202 | 2215 | | |
2203 | 2216 | | |
2204 | 2217 | | |
2205 | | - | |
| 2218 | + | |
| 2219 | + | |
2206 | 2220 | | |
2207 | | - | |
| 2221 | + | |
| 2222 | + | |
2208 | 2223 | | |
2209 | 2224 | | |
2210 | | - | |
| 2225 | + | |
2211 | 2226 | | |
2212 | 2227 | | |
2213 | 2228 | | |
| |||
2223 | 2238 | | |
2224 | 2239 | | |
2225 | 2240 | | |
2226 | | - | |
| 2241 | + | |
| 2242 | + | |
2227 | 2243 | | |
2228 | | - | |
| 2244 | + | |
| 2245 | + | |
2229 | 2246 | | |
2230 | 2247 | | |
2231 | | - | |
| 2248 | + | |
2232 | 2249 | | |
2233 | 2250 | | |
2234 | 2251 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
Lines changed: 90 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
603 | 603 | | |
604 | 604 | | |
605 | 605 | | |
| 606 | + | |
606 | 607 | | |
607 | 608 | | |
608 | 609 | | |
| |||
702 | 703 | | |
703 | 704 | | |
704 | 705 | | |
| 706 | + | |
| 707 | + | |
| 708 | + | |
| 709 | + | |
| 710 | + | |
| 711 | + | |
| 712 | + | |
| 713 | + | |
| 714 | + | |
| 715 | + | |
| 716 | + | |
| 717 | + | |
| 718 | + | |
| 719 | + | |
| 720 | + | |
| 721 | + | |
| 722 | + | |
| 723 | + | |
| 724 | + | |
| 725 | + | |
| 726 | + | |
| 727 | + | |
| 728 | + | |
| 729 | + | |
| 730 | + | |
| 731 | + | |
| 732 | + | |
| 733 | + | |
| 734 | + | |
| 735 | + | |
| 736 | + | |
| 737 | + | |
| 738 | + | |
| 739 | + | |
| 740 | + | |
| 741 | + | |
| 742 | + | |
| 743 | + | |
| 744 | + | |
| 745 | + | |
| 746 | + | |
| 747 | + | |
| 748 | + | |
| 749 | + | |
705 | 750 | | |
706 | 751 | | |
707 | 752 | | |
| |||
0 commit comments