Memory allocation in recursion

I was about to say “but julia doesn’t do TCO”. But you’re absolutely right, it is both educational and more readable / honest / transparent to write

function foo(x,y,x)
  #...
    return foo(a,b,c) # tail-call
  #...
end

as

function foo(x,y,z)
  @label entry
  #...
    x,y,z = a,b,c
    @goto entry
  #...
end

I would not be surprised if the recursion stumped escape analysis and caused views to be allocated instead of SROA-ed.

1 Like