I have a function inside a nested loop, and I’m cleaning it up with @unpack
from UnPack.jl for about 20 parametrs/pre-allocated matrix:
@unpack a,b,c = p #parameters...
@unpack m1,m2,m3 = p #pre-allocated matrices for things like mul!()
@code_llvm
suggests that the hand-written version (a=p.a
, b=p.b
, etc) generates more or less the same code as the cleaner @unpack
version, with only a few comments such as
; ┌ @ /Users/user/.julia/packages/UnPack/1IjJI/src/UnPack.jl:101 within `macro expansion'
; │┌ @ /Users/user/.julia/packages/UnPack/1IjJI/src/UnPack.jl:34 within `unpack'
testing with @benchmark
suggests there’s very little performance difference. Just to understand the inner workings, is having a macro equivalent to the expanded version from the compiler’s point of view, and there would be no performance penalties to use macros inside the nested/hot loop? Thanks!