Open mcabbott opened 5 days ago
This is quite a severe penalty, isn't it?
A lot of my code uses broadcast expressions with at least >5 dots. Replacing all of them with function calls is very unpractical.
A macro could in principle produce the scalarfun
form for you. Building this into @.
would be a bit scary (seems likely to expose all kinds of special assumptions in code). But the question before contemplating that is: Why can't the complicated form compile down to the same code?
This example from Discourse shows a slowdown when broadcasting a moderately complicated expression, instead of broadcasting a function containing the same expression:
The effect seems fairly robust, it's not particular to 3D arrays, nor to
A^2
. Replacing@.
with.+
etc. helps a bit (which according to #29120 removes n-ary+
, here n<=4):Simpler expressions also have the slowdown but no allocation:
Even simpler expressions like
arrayfun!(C, A, B) = @. C = A^2 + B^2
show no slowdown at all.