Yes, that boxing is done by the frontend and is exactly performance of captured variables in closures · Issue #15276 · JuliaLang/julia · GitHub. Note that the type stability of y
is irrelevant here, for example:
function f(x)
y = "a"
y = "b"
g(_) = y
return g(x)
end
will also cause a Box
.