You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
faster iteration over a Flatten of heterogenous iterators (JuliaLang#58522)
seems to help in many cases. would fix the precise MWE given in
JuliaLang#52552, but does not
necessarily fix comprehensively all perf issues of all heterogenous
flattens. but, may as well be better when it's possible
setup:
```
julia> using BenchmarkTools
julia> A = rand(Int, 100000); B = 1:100000;
julia> function g(it)
s = 0
for i in it
s += i
end
s
end
```
before:
```
julia> @Btime g($(Iterators.flatten((A, B))))
12.461 ms (698979 allocations: 18.29 MiB)
julia> @Btime g($(Iterators.flatten(i for i in (A, B))))
12.393 ms (698979 allocations: 18.29 MiB)
julia> @Btime g($(Iterators.flatten([A, B])))
15.115 ms (999494 allocations: 25.93 MiB)
julia> @Btime g($(Iterators.flatten((A, Iterators.flatten((A, B))))))
82.585 ms (2997964 allocations: 106.78 MiB)
```
after:
```
julia> @Btime g($(Iterators.flatten((A, B))))
135.958 μs (2 allocations: 64 bytes)
julia> @Btime g($(Iterators.flatten(i for i in (A, B))))
149.500 μs (2 allocations: 64 bytes)
julia> @Btime g($(Iterators.flatten([A, B])))
17.130 ms (999498 allocations: 25.93 MiB)
julia> @Btime g($(Iterators.flatten((A, Iterators.flatten((A, B))))))
13.716 ms (398983 allocations: 10.67 MiB)
```
0 commit comments