Is there a way for loop fusion in Julia to operate even recursively into function calls? By that I mean, consider,
julia> a=b=rand(2000,2000); julia> @time a.+b.+a; 0.064173 seconds (10.63 k allocations: 31.015 MiB, 2.54% gc time) julia> myplus(a,b) = a.+b myplus (generic function with 1 method) julia> @time a.+myplus(a,b); 0.058254 seconds (53 allocations: 61.037 MiB, 4.30% gc time)
Its clear the latter call wasn’t fused into a single loop since twice the memory was allocated.
My best guess is this isn’t supported, and maybe never will be because the ambiguity of what to do if
myplus has other side-effects. However, is there any way to make something similar to this work, to allow shorthand for some longer operation than
myplus? It certainly seems within the realm of reason that the compiler could figure out in simple cases like this that its safe to fuse.