function ffill(n,X)
A = Vector{Tuple{Int, Vector{Int}}}(n)
for i=1:n A[i] = (i,X) end
A
end
@time ffill(1000, collect(1:2))
0.000049 seconds (1.01 k allocations: 39.500 KiB)
Is this supposed to have changed? As in, have I somehow checked out the wrong branch?
Also, in this case the bad thing is not even the allocation but the extra indirection (hence cache miss) on access. Storing refs to arrays (instead of data-pointers) already gives me an indirection; the tuple-boxing gives me another one.
…I’d really like an immutable array, length+data-pointer, that keeps the data-pointed region alive. Sure, you can’t resize, but you lose one cache-missed indirection.
Currently I need a second data-structure just for gc-visibility and need to be very careful that both never go out of sync
Edit: Still allocates and stores boxed on feec0ecf1c0189f2b47aa05680ee16257692d19e from yesterday. But as a bonus,
A= ffill(1000, collect(1:2));
show(A)
throws:
Tuple{Int64,Array{Int64,1}}[(1, ERROR: AssertionError: Array{Int64,1} is not a subtype of Tuple{Int64,Array{Int64,1}}
Stacktrace:
[1] typeinfo_prefix(::IOContext{Base.TTY}, ::Array{Int64,1}) at ./arrayshow.jl:475
[2] show_vector(::IOContext{Base.TTY}, ::Array{Int64,1}, ::Char, ::Char) at ./arrayshow.jl:428 (repeats 2 times)
[3] show(::IOContext{Base.TTY}, ::Array{Int64,1}) at ./arrayshow.jl:442
[4] show_delim_array(::IOContext{Base.TTY}, ::Tuple{Int64,Array{Int64,1}}, ::Char, ::Char, ::Char, ::Bool, ::Int64, ::Int64) at ./show.jl:501
[5] show_delim_array at ./show.jl:489 [inlined]
[6] show at ./show.jl:517 [inlined]
[7] show_delim_array(::IOContext{Base.TTY}, ::Array{Tuple{Int64,Array{Int64,1}},1}, ::Char, ::String, ::Char, ::Bool, ::Int64, ::Int64) at ./show.jl:472
[8] show_delim_array at ./show.jl:458 [inlined]
[9] show_vector(::Base.TTY, ::Array{Tuple{Int64,Array{Int64,1}},1}, ::Char, ::Char) at ./arrayshow.jl:438
[10] show_vector at ./arrayshow.jl:428 [inlined]
[11] show(::Base.TTY, ::Array{Tuple{Int64,Array{Int64,1}},1}) at ./arrayshow.jl:442
[12] show(::Array{Tuple{Int64,Array{Int64,1}},1}) at ./show.jl:130
[13] top-level scope