JuliaArrays / JuliaArrays/StaticArrays.jl
Regression of `reduce` (formerly `reducedim`) in Julia 0.7
Nobody has claimed this yet.
- Dominant language
- Julia
- Stars
- 844
- Forks
- 159
- Avg merge
- 3d 21h
- Merged PRs (30d)
- 3
Description
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?
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by reproducing the Julia 0.6 reducedim and Julia 0.7 reduce(..., dims=Val(2)) benchmarks shown in the issue, including the allocation changes around m=3. No source files or tests are named, so trace the reduce implementation used by StaticArrays and compare its behavior with the older path. Done means the regression is explained and the affected operation is restored or its expected performance is documented.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- julia
- Domain
- performance
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100