Skip to content

Regression of reduce (formerly reducedim) in Julia 0.7 #498

Open
@wsshin

Description

@wsshin

I observe a significant regression in reduce in Julia 0.7 compared to reducedim in Julia 0.6. Below, I add the columns of an m×2 matrix to create an m×1 matrix for different values of m. In Julia 0.6,

julia> VERSION
v"0.6.3-pre.0"

julia> m = 1; A = @SMatrix rand(m, 2); @btime reducedim(+, $A, Val{2});
  1.894 ns (0 allocations: 0 bytes)

julia> m = 2; A = @SMatrix rand(m, 2); @btime reducedim(+, $A, Val{2});
  2.261 ns (0 allocations: 0 bytes)

julia> m = 3; A = @SMatrix rand(m, 2); @btime reducedim(+, $A, Val{2});
  2.261 ns (0 allocations: 0 bytes)

julia> m = 4; A = @SMatrix rand(m, 2); @btime reducedim(+, $A, Val{2});
  2.264 ns (0 allocations: 0 bytes)

julia> m = 5; A = @SMatrix rand(m, 2); @btime reducedim(+, $A, Val{2});
  2.634 ns (0 allocations: 0 bytes)

julia> m = 10; A = @SMatrix rand(m, 2); @btime reducedim(+, $A, Val{2});
  4.208 ns (0 allocations: 0 bytes)

On the other hand, in Julia 0.7:

julia> VERSION
v"0.7.1-pre.0"

julia> m = 1; A = @SMatrix rand(m, 2); @btime reduce(+, $A, dims=Val(2));
  8.015 ns (0 allocations: 0 bytes)

julia> m = 2; A = @SMatrix rand(m, 2); @btime reduce(+, $A, dims=Val(2));
  8.205 ns (0 allocations: 0 bytes)

julia> m = 3; A = @SMatrix rand(m, 2); @btime reduce(+, $A, dims=Val(2));
  210.229 ns (3 allocations: 160 bytes)

julia> m = 4; A = @SMatrix rand(m, 2); @btime reduce(+, $A, dims=Val(2));
  55.512 ns (2 allocations: 128 bytes)

julia> m = 5; A = @SMatrix rand(m, 2); @btime reduce(+, $A, dims=Val(2));
  44.934 ns (2 allocations: 144 bytes)

julia> m = 10; A = @SMatrix rand(m, 2); @btime reduce(+, $A, dims=Val(2));
  57.598 ns (2 allocations: 272 bytes)

Observations:

  • 0.6 does not use any allocations.
  • 0.7 starts using allocations for $m ≥ 3$, but even for $m ≤ 2$ for which no allocations are used, 0.7 is 3–4 times slower than 0.6.
  • There is something weird about $m = 3$ in 0.7: the code runs significantly slower for $m = 3$ than for $m > 3$, probably because it uses one more allocation for some reason.

Any idea why this regression occurs?

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions