Skip to content
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

Iteration causes many allocations #16

Open
roflmaostc opened this issue Jan 28, 2022 · 1 comment
Open

Iteration causes many allocations #16

roflmaostc opened this issue Jan 28, 2022 · 1 comment

Comments

@roflmaostc
Copy link
Member

roflmaostc commented Jan 28, 2022

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)
@RainerHeintzmann
Copy link
Member

Maybe we need to write a specialized iterator?
This code does not cause the extra allocations:

julia> @time sum(rr((1000,1000)) .> 100.0)
  0.001440 seconds (4 allocations: 126.406 KiB)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants