Consider code like
julia> function outer()
function inner()
false && inner()
end
inner
end
julia> typeof(outer()).types
svec(Core.Box)
So this kind of code creates a box for the local variable inner
which is captured by inner
itself, because it is needed in the method body of inner()
.
Alas, I see no obvious way of using let
blocks to avoid the boxing.
So my questions are:
- is this kind of boxing semantically necessary?
- is this a recent lowering bug?
- is there a nice trick to avoid the boxing?
- is this a missing point in Performance Tips · The Julia Language ?
If this was my own personal code, I wouldn’t particularly care and just use an explicit callable struct. But that is inappropriate for shared projects (drive-by-fixes on github are nice, drive-by-refactorings are obnoxious).
An example in the wild is julia/base/file.jl at 9b1ea1a880e1c47ebdc549a12fca288b5cc60013 · JuliaLang/julia · GitHub where the local variable _walkdir
is boxed due to the reentrency of the _walkdir
method body.
Apologies if I failed to find prior discussions on that – I’d also appreciate a pointer.