Commit 04ce680
KT-75801: optimize functions converting object array to list
This contains two different cases of optimization:
* Array<T>.(take|takeLast|takeWhile) functions : replace loop copy with copyOfRange().asList()
* Array<T>.toList() and Array<Array<T>>.flatten() : force using direct array copy instead of delegating to mutable list.
Primitive array functions were not modified, because of unboxing. When the optimization is applied to primitive arrays, the initial copy might indeed get faster, but then, unboxing would be delayed on List.get() calls, therefore adding performance penalty on the consumer side.
Benchmarks being used:
- original set of benchmarks: https://github.com/alexismanin/kt-benchmark-array-to-list
- later validated on: https://github.com/fzhinkin/kt-benchmark-array-to-list/tree/run-filter-on-pre-allocated-list
^KT-75801 Fixed
^KT-82033 Fixed
Initial GH PR: #5426
Merge-request: KT-MR-21026
Merged-by: Filipp Zhinkin <[email protected]>1 parent 8131c51 commit 04ce680
File tree
4 files changed
+70
-27
lines changed- libraries
- stdlib
- common/src/generated
- src/kotlin/collections
- tools/kotlin-stdlib-gen/src/templates
4 files changed
+70
-27
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
4944 | 4944 | | |
4945 | 4945 | | |
4946 | 4946 | | |
4947 | | - | |
4948 | | - | |
4949 | | - | |
4950 | | - | |
4951 | | - | |
4952 | | - | |
4953 | | - | |
4954 | | - | |
| 4947 | + | |
4955 | 4948 | | |
4956 | 4949 | | |
4957 | 4950 | | |
| |||
5143 | 5136 | | |
5144 | 5137 | | |
5145 | 5138 | | |
5146 | | - | |
5147 | | - | |
5148 | | - | |
5149 | | - | |
| 5139 | + | |
5150 | 5140 | | |
5151 | 5141 | | |
5152 | 5142 | | |
| |||
5433 | 5423 | | |
5434 | 5424 | | |
5435 | 5425 | | |
5436 | | - | |
5437 | | - | |
5438 | | - | |
5439 | | - | |
5440 | | - | |
5441 | | - | |
5442 | | - | |
| 5426 | + | |
| 5427 | + | |
| 5428 | + | |
| 5429 | + | |
| 5430 | + | |
5443 | 5431 | | |
5444 | 5432 | | |
5445 | 5433 | | |
| |||
10277 | 10265 | | |
10278 | 10266 | | |
10279 | 10267 | | |
10280 | | - | |
| 10268 | + | |
10281 | 10269 | | |
10282 | 10270 | | |
10283 | 10271 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
17 | 17 | | |
18 | 18 | | |
19 | 19 | | |
20 | | - | |
21 | | - | |
22 | | - | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
23 | 24 | | |
24 | | - | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
25 | 35 | | |
26 | 36 | | |
27 | 37 | | |
| |||
Lines changed: 37 additions & 2 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
192 | 192 | | |
193 | 193 | | |
194 | 194 | | |
195 | | - | |
| 195 | + | |
196 | 196 | | |
197 | 197 | | |
198 | 198 | | |
| |||
208 | 208 | | |
209 | 209 | | |
210 | 210 | | |
| 211 | + | |
| 212 | + | |
| 213 | + | |
| 214 | + | |
| 215 | + | |
| 216 | + | |
| 217 | + | |
| 218 | + | |
| 219 | + | |
| 220 | + | |
| 221 | + | |
211 | 222 | | |
212 | 223 | | |
213 | 224 | | |
| |||
270 | 281 | | |
271 | 282 | | |
272 | 283 | | |
273 | | - | |
| 284 | + | |
274 | 285 | | |
275 | 286 | | |
276 | 287 | | |
| |||
284 | 295 | | |
285 | 296 | | |
286 | 297 | | |
| 298 | + | |
| 299 | + | |
| 300 | + | |
| 301 | + | |
| 302 | + | |
| 303 | + | |
| 304 | + | |
| 305 | + | |
| 306 | + | |
| 307 | + | |
| 308 | + | |
| 309 | + | |
| 310 | + | |
287 | 311 | | |
288 | 312 | | |
289 | 313 | | |
| |||
413 | 437 | | |
414 | 438 | | |
415 | 439 | | |
| 440 | + | |
| 441 | + | |
| 442 | + | |
| 443 | + | |
| 444 | + | |
| 445 | + | |
| 446 | + | |
| 447 | + | |
| 448 | + | |
| 449 | + | |
| 450 | + | |
416 | 451 | | |
417 | 452 | | |
418 | 453 | | |
| |||
Lines changed: 11 additions & 1 deletion
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
174 | 174 | | |
175 | 175 | | |
176 | 176 | | |
177 | | - | |
| 177 | + | |
178 | 178 | | |
179 | 179 | | |
180 | 180 | | |
| |||
183 | 183 | | |
184 | 184 | | |
185 | 185 | | |
| 186 | + | |
| 187 | + | |
| 188 | + | |
| 189 | + | |
| 190 | + | |
| 191 | + | |
| 192 | + | |
| 193 | + | |
| 194 | + | |
| 195 | + | |
186 | 196 | | |
187 | 197 | | |
188 | 198 | | |
| |||
0 commit comments