Skip to content

Iteration causes many allocations #16

@roflmaostc

Description

@roflmaostc

Some IFAs such as (rr2, rr, normal) cause allocations.
Strangely, window_hamming doesn't.

using IndexFunArrays


function main_bug(; N=4096)
    els = rr2(Int, (N, N)) 

    s = zero(eltype(els))

    for e in els 
        if e > 100
            s += 1
        end 
    end 
    return s
end

# 
julia> @time main_bug(; N=1000)
  0.061883 seconds (3.00 M allocations: 106.787 MiB, 22.70% gc time)

collecting fixes it, so it is related to IndexFunArrays.

using IndexFunArrays


function main_bug(; N=4096)
    els = collect(rr2(Int, (N, N)))

    s = zero(eltype(els))

    for e in els 
        if e > 100
            s += 1
        end 
    end 
    return s
end

# 
julia> @time main_bug(; N=1000)
  0.007953 seconds (7 allocations: 7.630 MiB, 84.24% gc time)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions