-
-
Notifications
You must be signed in to change notification settings - Fork 5.5k
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
unnecessary allocations in broadcast!
?
#19608
Comments
Strangely julia> VERSION
v"0.6.0-dev.1557"
julia> using BenchmarkTools
julia> q = [0, 0, 0];
julia> @benchmark broadcast!(z -> 2z+1, $q, $q)
BenchmarkTools.Trial:
samples: 10000
evals/sample: 997
time tolerance: 5.00%
memory tolerance: 1.00%
memory estimate: 0.00 bytes
allocs estimate: 0
minimum time: 21.00 ns (0.00% GC)
median time: 21.00 ns (0.00% GC)
mean time: 22.61 ns (0.00% GC)
maximum time: 193.00 ns (0.00% GC) Perhaps the allocation in the example above is elsewhere? Best! |
This is caused by the allocation of |
So, basically we need some improved loop hoisting for the compiler to recognize that |
(I thought Julia didn't need to do a heap allocation for local tuples?) |
I doubt hoisting is the most useful optimization in this case (it certainly is useful) since it will breakdown if x is assigned to. The tuple isn't tuple since it is somehow passed to a |
So maybe we just need to add |
That's most likely |
This might be the cause Line 132 in d76388f
|
Why do we have the |
(useful tip - hit Line 132 in d76388f
|
This comment might be the answer? Best! |
Since that comment is for code that seems to have been deleted, maybe it is no longer relevant? Regardless, I just tried removing the |
I think I have a fix. Will submit a PR (#19639) |
Closed by #19639. |
The
broadcast!
function seems like it allocates memory, e.g. in the following example it apparently allocates about 16 bytes per loop iteration.It seems like this should be something that can be eliminated.
cc @pabloferz
The text was updated successfully, but these errors were encountered: