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

"A[:] = ..." allocates memory #16302

Closed
stevengj opened this issue May 10, 2016 · 3 comments
Closed

"A[:] = ..." allocates memory #16302

stevengj opened this issue May 10, 2016 · 3 comments
Labels
performance Must go faster

Comments

@stevengj
Copy link
Member

It seems like this construct should operate in-place, but it apparently doesn't:

function foo(A)
    for i = 1:10^6
        A[:] = 0
    end
end
@time foo([3,4,5])

gives

0.021217 seconds (1.00 M allocations: 15.259 MB, 23.12% gc time)

Notice that it is apparently allocating something on each loop iteration. (Same on 0.4 and 0.5.)

@stevengj stevengj added the performance Must go faster label May 10, 2016
@yuyichao
Copy link
Contributor

The allocation is caused by the vararg call.

@stevengj
Copy link
Member Author

We should have a specialized setindex method for this case that just calls fill!.

@yuyichao
Copy link
Contributor

Ref #13459 (comment) , maybe .... It looks like we are getting close to fix #13359 though....

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

No branches or pull requests

2 participants