The short answer is that there is a certain set of optimizations that have
been implemented in Julia, but still a considerable set that has not been
implemented. This falls into the category of optimizations that have not
been implemented. Pull requests are always welcome (although I do not
recommend this one as a good beginner / "up-for-grabs" issue).

On Thu, Apr 23, 2015 at 9:18 AM Mauro <[email protected]> wrote:

> It is well know that Julia struggles with type inference in higher order
> functions.  This usually leads to slow code and memory allocations.
> There are a few hacks to work around this.  Anyway, the question I have
> is: Why can't Julia do better with in-place functions?
>
> In short, a higher-order function like this:
>
> function f(fn!,ar)
>     for i=1:n
>         fn!(ar, i) # fn! updates ar[i] somehow, returns nothing
>         nothing    # to make sure output of f is discarded
>     end
> end
>
> has almost as bad a performance (runtime and allocation-wise) as
>
> function g(fn,ar)
>     for i=1:n
>         ar[i] = fn(ar[i])
>     end
> end
>
> A in-depth, ready to run example is here:
> https://gist.github.com/mauro3/f17da10247b0bad96f1a
> Including output of @code_warntype.
>
> So, why is Julia allocating memory when running f?  Nothing of f gets
> assigned to anything.
>
> Would this be something which is fixable more easily than the whole of
> the higher-order performance issues?  If so, is there an issue for this?
>
> Having good in-place higher order functions would go a long way with
> numerical computations.  Thanks!
>

Reply via email to