The observation about “bad” is correct, though it is almost exponential, not quadratic:
julia> struct A{T}
x::T
end
julia> function foo(x0, n)
b = A(x0)
while n > 0
b = A(b)
n -= 1
end
b
end
foo (generic function with 1 method)
julia> for len in [100, 120, 140, 160, 180, 200, 220, 240, 260, 280, 300]
@show len
foo(0, len);
@time foo(0, len+1);
nothing
end
len = 100
0.040797 seconds (1.57 k allocations: 102.184 KiB, 99.60% compilation time)
len = 120
0.074160 seconds (1.59 k allocations: 102.496 KiB, 99.73% compilation time)
len = 140
0.124817 seconds (1.61 k allocations: 102.809 KiB, 99.77% compilation time)
len = 160
0.202185 seconds (1.63 k allocations: 103.121 KiB, 99.80% compilation time)
len = 180
0.303983 seconds (1.65 k allocations: 103.434 KiB, 99.82% compilation time)
len = 200
0.445882 seconds (1.67 k allocations: 103.746 KiB, 99.86% compilation time)
len = 220
0.625526 seconds (1.69 k allocations: 104.059 KiB, 99.88% compilation time)
len = 240
0.859999 seconds (1.71 k allocations: 104.371 KiB, 99.90% compilation time)
len = 260
1.167733 seconds (1.73 k allocations: 104.692 KiB, 99.91% compilation time)
len = 280
1.539299 seconds (1.75 k allocations: 105.005 KiB, 99.92% compilation time)
len = 300
2.024749 seconds (1.77 k allocations: 112.567 KiB, 99.93% compilation time)
If I now copy-paste the times into an array,
julia> rs = [0.040797, 0.074160, 0.124817, 0.202185, 0.303983, 0.445882, 0.625526, 0.859999, 1.167733, 1.539299, 2.024749];
julia> [rs[i+1]/rs[i] for i=1:(length(rs)-1)]
10-element Vector{Float64}:
1.8177807191705273
1.6830771305285868
1.6198514625411604
1.5034893785394565
1.4667991302145185
1.4028958334267811
1.374841333533698
1.3578306486402891
1.318194313254828
1.3153708278898382
I think this is well-known here? I.e. compilation time is often exponential in complexity of the type, especially for layouting of data types. It’s one of the reasons one shouldn’t go overboard with complex types or large / nested SVectors.
If this is not well-known, we should may split it off @mbauman