JuliaFolds / Transducers.jl

Efficient transducers for Julia
https://juliafolds.github.io/Transducers.jl/dev/
MIT License
433 stars 24 forks source link

High allocations in `Zip()` #564

Open artemsolod opened 11 months ago

artemsolod commented 11 months ago

Zip(x, y) allocates a lot in a simple use case (foo). Zip(x) with a single argument seems ok. System: julia 1.9.3, Transducers v0.4.78, Ubuntu

julia> using Transducers, BenchmarkTools

julia> foo(vals) = vals |> Zip(Map(identity), Map(identity)) |> collect
foo (generic function with 1 method)

julia> vals = collect(1:10_000);

julia> @btime foo($vals); # Zip(x, y)
  6.014 ms (150060 allocations: 5.22 MiB)

julia> foo1(vals) = vals |> Zip(Map(identity)) |> collect
foo1 (generic function with 1 method)

julia> @btime foo1($vals); # Zip(x)
  205.577 μs (17 allocations: 326.78 KiB)