Commit d9bc548
authored
[libc++] Optimize __tree::find and __tree::__erase_unique (#152370)
This patch changes `__tree::find` to return when it has found any equal
element instead of the lower bound of the equal elements. For `map` and
`set` there is no observable difference, since the keys are unique.
However for their `multi` versions this can mean a change in behaviour
since it's not longer guaranteed that `find` will return the first
element.
```
------------------------------------------------------------------------------------------
Benchmark old new
------------------------------------------------------------------------------------------
std::map<int, int>::erase(key) (existent)/0 24.4 ns 24.9 ns
std::map<int, int>::erase(key) (existent)/32 39.8 ns 32.1 ns
std::map<int, int>::erase(key) (existent)/1024 83.8 ns 52.5 ns
std::map<int, int>::erase(key) (existent)/8192 91.4 ns 66.4 ns
std::map<int, int>::erase(key) (non-existent)/0 0.511 ns 0.328 ns
std::map<int, int>::erase(key) (non-existent)/32 9.12 ns 5.62 ns
std::map<int, int>::erase(key) (non-existent)/1024 26.6 ns 11.3 ns
std::map<int, int>::erase(key) (non-existent)/8192 37.0 ns 16.9 ns
std::map<int, int>::find(key) (existent)/0 0.007 ns 0.007 ns
std::map<int, int>::find(key) (existent)/32 6.02 ns 4.32 ns
std::map<int, int>::find(key) (existent)/1024 13.6 ns 8.35 ns
std::map<int, int>::find(key) (existent)/8192 30.3 ns 12.8 ns
std::map<int, int>::find(key) (non-existent)/0 0.299 ns 0.545 ns
std::map<int, int>::find(key) (non-existent)/32 8.78 ns 4.60 ns
std::map<int, int>::find(key) (non-existent)/1024 26.1 ns 21.8 ns
std::map<int, int>::find(key) (non-existent)/8192 36.2 ns 27.9 ns
std::map<std::string, int>::erase(key) (existent)/0 74.1 ns 76.7 ns
std::map<std::string, int>::erase(key) (existent)/32 161 ns 114 ns
std::map<std::string, int>::erase(key) (existent)/1024 196 ns 126 ns
std::map<std::string, int>::erase(key) (existent)/8192 207 ns 160 ns
std::map<std::string, int>::erase(key) (non-existent)/0 0.754 ns 0.328 ns
std::map<std::string, int>::erase(key) (non-existent)/32 47.3 ns 40.7 ns
std::map<std::string, int>::erase(key) (non-existent)/1024 122 ns 96.1 ns
std::map<std::string, int>::erase(key) (non-existent)/8192 168 ns 123 ns
std::map<std::string, int>::find(key) (existent)/0 0.059 ns 0.058 ns
std::map<std::string, int>::find(key) (existent)/32 54.3 ns 34.6 ns
std::map<std::string, int>::find(key) (existent)/1024 125 ns 64.5 ns
std::map<std::string, int>::find(key) (existent)/8192 159 ns 79.2 ns
std::map<std::string, int>::find(key) (non-existent)/0 0.311 ns 0.299 ns
std::map<std::string, int>::find(key) (non-existent)/32 44.0 ns 42.7 ns
std::map<std::string, int>::find(key) (non-existent)/1024 120 ns 92.6 ns
std::map<std::string, int>::find(key) (non-existent)/8192 189 ns 124 ns
std::set<int>::erase(key) (existent)/0 25.1 ns 25.1 ns
std::set<int>::erase(key) (existent)/32 42.1 ns 33.1 ns
std::set<int>::erase(key) (existent)/1024 73.8 ns 55.5 ns
std::set<int>::erase(key) (existent)/8192 101 ns 68.8 ns
std::set<int>::erase(key) (non-existent)/0 0.511 ns 0.328 ns
std::set<int>::erase(key) (non-existent)/32 9.60 ns 4.67 ns
std::set<int>::erase(key) (non-existent)/1024 26.5 ns 11.2 ns
std::set<int>::erase(key) (non-existent)/8192 46.2 ns 16.8 ns
std::set<int>::find(key) (existent)/0 0.008 ns 0.007 ns
std::set<int>::find(key) (existent)/32 5.87 ns 4.51 ns
std::set<int>::find(key) (existent)/1024 14.3 ns 8.69 ns
std::set<int>::find(key) (existent)/8192 30.2 ns 12.8 ns
std::set<int>::find(key) (non-existent)/0 0.531 ns 0.530 ns
std::set<int>::find(key) (non-existent)/32 8.77 ns 4.64 ns
std::set<int>::find(key) (non-existent)/1024 26.1 ns 21.7 ns
std::set<int>::find(key) (non-existent)/8192 36.3 ns 27.8 ns
std::set<std::string>::erase(key) (existent)/0 93.2 ns 70.2 ns
std::set<std::string>::erase(key) (existent)/32 164 ns 116 ns
std::set<std::string>::erase(key) (existent)/1024 161 ns 136 ns
std::set<std::string>::erase(key) (existent)/8192 231 ns 140 ns
std::set<std::string>::erase(key) (non-existent)/0 0.532 ns 0.326 ns
std::set<std::string>::erase(key) (non-existent)/32 43.4 ns 40.1 ns
std::set<std::string>::erase(key) (non-existent)/1024 122 ns 99.5 ns
std::set<std::string>::erase(key) (non-existent)/8192 168 ns 125 ns
std::set<std::string>::find(key) (existent)/0 0.059 ns 0.059 ns
std::set<std::string>::find(key) (existent)/32 53.1 ns 35.5 ns
std::set<std::string>::find(key) (existent)/1024 124 ns 61.2 ns
std::set<std::string>::find(key) (existent)/8192 154 ns 73.9 ns
std::set<std::string>::find(key) (non-existent)/0 0.532 ns 0.301 ns
std::set<std::string>::find(key) (non-existent)/32 44.4 ns 39.5 ns
std::set<std::string>::find(key) (non-existent)/1024 120 ns 95.5 ns
std::set<std::string>::find(key) (non-existent)/8192 193 ns 119 ns
std::multimap<int, int>::erase(key) (existent)/0 26.5 ns 26.6 ns
std::multimap<int, int>::erase(key) (existent)/32 33.5 ns 32.9 ns
std::multimap<int, int>::erase(key) (existent)/1024 55.5 ns 58.0 ns
std::multimap<int, int>::erase(key) (existent)/8192 67.4 ns 70.0 ns
std::multimap<int, int>::erase(key) (non-existent)/0 0.523 ns 0.532 ns
std::multimap<int, int>::erase(key) (non-existent)/32 5.08 ns 5.09 ns
std::multimap<int, int>::erase(key) (non-existent)/1024 13.0 ns 12.9 ns
std::multimap<int, int>::erase(key) (non-existent)/8192 19.6 ns 19.8 ns
std::multimap<int, int>::find(key) (existent)/0 0.015 ns 0.037 ns
std::multimap<int, int>::find(key) (existent)/32 7.07 ns 3.85 ns
std::multimap<int, int>::find(key) (existent)/1024 22.0 ns 7.44 ns
std::multimap<int, int>::find(key) (existent)/8192 37.6 ns 12.0 ns
std::multimap<int, int>::find(key) (non-existent)/0 0.297 ns 0.305 ns
std::multimap<int, int>::find(key) (non-existent)/32 8.79 ns 4.59 ns
std::multimap<int, int>::find(key) (non-existent)/1024 26.0 ns 11.2 ns
std::multimap<int, int>::find(key) (non-existent)/8192 36.4 ns 16.8 ns
std::multimap<std::string, int>::erase(key) (existent)/0 93.4 ns 84.5 ns
std::multimap<std::string, int>::erase(key) (existent)/32 101 ns 101 ns
std::multimap<std::string, int>::erase(key) (existent)/1024 118 ns 126 ns
std::multimap<std::string, int>::erase(key) (existent)/8192 108 ns 124 ns
std::multimap<std::string, int>::erase(key) (non-existent)/0 2.39 ns 2.43 ns
std::multimap<std::string, int>::erase(key) (non-existent)/32 44.4 ns 49.7 ns
std::multimap<std::string, int>::erase(key) (non-existent)/1024 108 ns 103 ns
std::multimap<std::string, int>::erase(key) (non-existent)/8192 140 ns 125 ns
std::multimap<std::string, int>::find(key) (existent)/0 0.059 ns 0.058 ns
std::multimap<std::string, int>::find(key) (existent)/32 52.3 ns 32.6 ns
std::multimap<std::string, int>::find(key) (existent)/1024 122 ns 58.9 ns
std::multimap<std::string, int>::find(key) (existent)/8192 160 ns 72.7 ns
std::multimap<std::string, int>::find(key) (non-existent)/0 0.524 ns 0.494 ns
std::multimap<std::string, int>::find(key) (non-existent)/32 43.8 ns 38.9 ns
std::multimap<std::string, int>::find(key) (non-existent)/1024 123 ns 90.8 ns
std::multimap<std::string, int>::find(key) (non-existent)/8192 190 ns 126 ns
std::multiset<int>::erase(key) (existent)/0 27.1 ns 26.8 ns
std::multiset<int>::erase(key) (existent)/32 33.3 ns 34.1 ns
std::multiset<int>::erase(key) (existent)/1024 58.5 ns 58.8 ns
std::multiset<int>::erase(key) (existent)/8192 66.7 ns 64.1 ns
std::multiset<int>::erase(key) (non-existent)/0 0.318 ns 0.325 ns
std::multiset<int>::erase(key) (non-existent)/32 5.15 ns 5.25 ns
std::multiset<int>::erase(key) (non-existent)/1024 12.9 ns 12.7 ns
std::multiset<int>::erase(key) (non-existent)/8192 20.3 ns 20.3 ns
std::multiset<int>::find(key) (existent)/0 0.043 ns 0.015 ns
std::multiset<int>::find(key) (existent)/32 6.94 ns 4.22 ns
std::multiset<int>::find(key) (existent)/1024 21.4 ns 8.23 ns
std::multiset<int>::find(key) (existent)/8192 37.4 ns 12.6 ns
std::multiset<int>::find(key) (non-existent)/0 0.515 ns 0.300 ns
std::multiset<int>::find(key) (non-existent)/32 8.52 ns 4.62 ns
std::multiset<int>::find(key) (non-existent)/1024 25.5 ns 11.3 ns
std::multiset<int>::find(key) (non-existent)/8192 36.5 ns 27.0 ns
std::multiset<std::string>::erase(key) (existent)/0 81.9 ns 77.5 ns
std::multiset<std::string>::erase(key) (existent)/32 113 ns 129 ns
std::multiset<std::string>::erase(key) (existent)/1024 132 ns 148 ns
std::multiset<std::string>::erase(key) (existent)/8192 114 ns 165 ns
std::multiset<std::string>::erase(key) (non-existent)/0 2.33 ns 2.32 ns
std::multiset<std::string>::erase(key) (non-existent)/32 44.4 ns 42.0 ns
std::multiset<std::string>::erase(key) (non-existent)/1024 97.3 ns 95.1 ns
std::multiset<std::string>::erase(key) (non-existent)/8192 132 ns 123 ns
std::multiset<std::string>::find(key) (existent)/0 0.058 ns 0.059 ns
std::multiset<std::string>::find(key) (existent)/32 48.3 ns 34.4 ns
std::multiset<std::string>::find(key) (existent)/1024 121 ns 61.9 ns
std::multiset<std::string>::find(key) (existent)/8192 155 ns 77.7 ns
std::multiset<std::string>::find(key) (non-existent)/0 0.524 ns 0.306 ns
std::multiset<std::string>::find(key) (non-existent)/32 44.1 ns 40.4 ns
std::multiset<std::string>::find(key) (non-existent)/1024 121 ns 96.3 ns
std::multiset<std::string>::find(key) (non-existent)/8192 193 ns 121 ns
```1 parent cbbf303 commit d9bc548
File tree
3 files changed
+47
-42
lines changed- libcxx
- docs/ReleaseNotes
- include
- test/std/containers/associative/multimap/multimap.ops
3 files changed
+47
-42
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
47 | 47 | | |
48 | 48 | | |
49 | 49 | | |
| 50 | + | |
| 51 | + | |
50 | 52 | | |
51 | 53 | | |
52 | 54 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1038 | 1038 | | |
1039 | 1039 | | |
1040 | 1040 | | |
1041 | | - | |
| 1041 | + | |
| 1042 | + | |
| 1043 | + | |
| 1044 | + | |
| 1045 | + | |
| 1046 | + | |
| 1047 | + | |
| 1048 | + | |
1042 | 1049 | | |
1043 | | - | |
| 1050 | + | |
| 1051 | + | |
| 1052 | + | |
| 1053 | + | |
| 1054 | + | |
| 1055 | + | |
| 1056 | + | |
1044 | 1057 | | |
1045 | 1058 | | |
1046 | 1059 | | |
| |||
2060 | 2073 | | |
2061 | 2074 | | |
2062 | 2075 | | |
2063 | | - | |
2064 | | - | |
2065 | | - | |
2066 | | - | |
2067 | | - | |
2068 | | - | |
2069 | | - | |
2070 | | - | |
2071 | | - | |
2072 | | - | |
2073 | | - | |
2074 | | - | |
2075 | | - | |
2076 | | - | |
2077 | | - | |
2078 | | - | |
2079 | | - | |
2080 | | - | |
2081 | | - | |
2082 | 2076 | | |
2083 | 2077 | | |
2084 | 2078 | | |
| |||
Lines changed: 30 additions & 21 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
21 | 21 | | |
22 | 22 | | |
23 | 23 | | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
24 | 33 | | |
25 | 34 | | |
26 | 35 | | |
| |||
30 | 39 | | |
31 | 40 | | |
32 | 41 | | |
33 | | - | |
| 42 | + | |
34 | 43 | | |
35 | 44 | | |
36 | 45 | | |
37 | | - | |
| 46 | + | |
38 | 47 | | |
39 | 48 | | |
40 | 49 | | |
41 | | - | |
| 50 | + | |
42 | 51 | | |
43 | 52 | | |
44 | 53 | | |
| |||
47 | 56 | | |
48 | 57 | | |
49 | 58 | | |
50 | | - | |
| 59 | + | |
51 | 60 | | |
52 | 61 | | |
53 | 62 | | |
54 | | - | |
| 63 | + | |
55 | 64 | | |
56 | 65 | | |
57 | 66 | | |
58 | | - | |
| 67 | + | |
59 | 68 | | |
60 | 69 | | |
61 | 70 | | |
| |||
68 | 77 | | |
69 | 78 | | |
70 | 79 | | |
71 | | - | |
| 80 | + | |
72 | 81 | | |
73 | 82 | | |
74 | 83 | | |
75 | | - | |
| 84 | + | |
76 | 85 | | |
77 | 86 | | |
78 | 87 | | |
79 | | - | |
| 88 | + | |
80 | 89 | | |
81 | 90 | | |
82 | 91 | | |
| |||
85 | 94 | | |
86 | 95 | | |
87 | 96 | | |
88 | | - | |
| 97 | + | |
89 | 98 | | |
90 | 99 | | |
91 | 100 | | |
92 | | - | |
| 101 | + | |
93 | 102 | | |
94 | 103 | | |
95 | 104 | | |
96 | | - | |
| 105 | + | |
97 | 106 | | |
98 | 107 | | |
99 | 108 | | |
| |||
107 | 116 | | |
108 | 117 | | |
109 | 118 | | |
110 | | - | |
| 119 | + | |
111 | 120 | | |
112 | 121 | | |
113 | 122 | | |
114 | | - | |
| 123 | + | |
115 | 124 | | |
116 | 125 | | |
117 | 126 | | |
118 | | - | |
| 127 | + | |
119 | 128 | | |
120 | 129 | | |
121 | 130 | | |
122 | 131 | | |
123 | | - | |
| 132 | + | |
124 | 133 | | |
125 | 134 | | |
126 | 135 | | |
127 | | - | |
| 136 | + | |
128 | 137 | | |
129 | 138 | | |
130 | 139 | | |
131 | | - | |
| 140 | + | |
132 | 141 | | |
133 | 142 | | |
134 | 143 | | |
| |||
150 | 159 | | |
151 | 160 | | |
152 | 161 | | |
153 | | - | |
| 162 | + | |
154 | 163 | | |
155 | 164 | | |
156 | 165 | | |
157 | | - | |
| 166 | + | |
158 | 167 | | |
159 | 168 | | |
160 | 169 | | |
161 | | - | |
| 170 | + | |
162 | 171 | | |
163 | 172 | | |
164 | 173 | | |
| |||
0 commit comments