-
-
Notifications
You must be signed in to change notification settings - Fork 5.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Showing a user defined abstract array takes a very long time #20832
Comments
I'd bet that this is effectively the same as #20334 (comment) — we seem to be sitting right on the edge of some catastrophically bad inference behavior. Once it's inferred, the second call takes less than 10 ms. |
Doing something like: Base.size{dim}(::Tensor{1, dim}) = (dim,)
Base.size{dim}(::Tensor{2, dim}) = (dim, dim)
Base.size{dim}(::Tensor{3, dim}) = (dim, dim, dim)
Base.size{dim}(::Tensor{4, dim}) = (dim, dim, dim, dim)
for i in 1:4
@time show(DevNull, Tensor{i, 3, Float64, 1}((rand(1)...)));
end gives: 0.329113 seconds (172.88 k allocations: 7.538 MiB)
0.384870 seconds (179.73 k allocations: 7.736 MiB, 28.97% gc time)
24.560876 seconds (90.18 M allocations: 4.039 GiB, 4.27% gc time)
1.823787 seconds (1.87 M allocations: 90.867 MiB, 2.73% gc time) Some new path when rank = 3? |
Yes, there's a codepath in |
Minimal reproduction: julia> struct T <: AbstractArray{Int,1}; end
Base.size(::T) = (1,)
julia> f1(I...) = Base.index_ndims(I...)
@time f1(1)
0.005126 seconds (1.41 k allocations: 81.339 KiB)
(true,)
julia> f2(A, n) = Base._maybe_reshape_parent(A, n);
@time f2(T(), (true,));
0.001032 seconds (634 allocations: 38.453 KiB)
julia> f3(A, I...) = Base._maybe_reshape_parent(A, Base.index_ndims(I...))
@time f3(T(), 1);
32.339036 seconds (55.48 M allocations: 2.480 GiB, 2.98% gc time) |
Fixed by #20874? Or is there more that could be done for this issue? On master I get for the example in OP: and the example from #20832 (comment) julia> @time f3(T(), 1);
0.120183 seconds (184.32 k allocations: 8.861 MiB) |
Can probably close then. 1 second is still quite long but it is at least in the ball park of 0.5 now. |
The following:
takes the following time on 0.6:
The equivalent code on 0.5 takes:
#20792 made no difference
The text was updated successfully, but these errors were encountered: