You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Julia "lowers" function calls with ... in it to an internal function called apply. As an internal function it knows how to deal with tuples but otherwise falls back to the iteration protocol (constructing an intermediate boxed tuple).
This can be a bit surpising since it (a) works correctly, (b) ... in slurping and destructuring there is no such efficiency problem, and (c) Julia does a pretty good job of avoiding performance gotchas in general. Fixing this would be the realm of the compiler developers, unfortunately. As you noted, the second one works fine; @c42f even suggested to have "lowering" wrap splats into an overloadable generic function that constructs a tuple from an iterable so you essentially always get the second case, which is an idea I have been warming to.
Summary: type inference needs to model the iteration protocol because splatting is defined in terms of iteration. (There's other implementation options, but they all seem to have some undesirable properties.)
I was surprised that
f()
allocated. I was even more surprised when I found out thatg()
does not:The text was updated successfully, but these errors were encountered: