Commit f82f2c7
Optimize Enum.unzip/1 for lists (#10963)
The existing unzip implementation is generic for all enumerable types.
However, large optimizations are available if the input is a list.
First, instead of doing two reverse operations at the end, we can do
one at the beginning. This optimization is unavailable in the existing
generic implementation in order to avoid materializing an enumerable
that might be generated lazily.
Second, we can accumulate the two output lists in two separate parameters,
rather than in the reduce function's accumulator. This avoids generating a
tuple per input element that would just be matched away and discarded
by Enum.reduce/3.
Testing with Benchfella shows a roughly 2x to 3x performance improvement
depending on the size of the list.1 parent 63e6f24 commit f82f2c7
1 file changed
+17
-0
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
3352 | 3352 | | |
3353 | 3353 | | |
3354 | 3354 | | |
| 3355 | + | |
| 3356 | + | |
| 3357 | + | |
| 3358 | + | |
| 3359 | + | |
| 3360 | + | |
| 3361 | + | |
| 3362 | + | |
| 3363 | + | |
3355 | 3364 | | |
3356 | 3365 | | |
3357 | 3366 | | |
| |||
3361 | 3370 | | |
3362 | 3371 | | |
3363 | 3372 | | |
| 3373 | + | |
| 3374 | + | |
| 3375 | + | |
| 3376 | + | |
| 3377 | + | |
| 3378 | + | |
| 3379 | + | |
| 3380 | + | |
3364 | 3381 | | |
3365 | 3382 | | |
3366 | 3383 | | |
| |||
0 commit comments