Parsimonious way to unpack big structs

No, @unpack is a macro and expands essentially to the same code. Have checked for SimpleUnPack.@unpack and Parameters.@unpack and all of these functions reduce to the same code, i.e., at the level of @code_typed:

function unpack_1(p)
    Parameters.@unpack α, β, γ = p
    α + β + γ
end
function unpack_2(p)
    SimpleUnPack.@unpack α, β, γ = p
    α + β + γ
end
function unpack_3(p)
    α, β, γ = p.α, p.β, p.γ
    α + β + γ
end

In any case, you can always check fo yourself:

julia> @code_typed unpack_1(p)
CodeInfo(
1 ─ %1 = Base.getfield(p, :α)::Any
│   %2 = Base.getfield(p, :β)::Any
│   %3 = Base.getfield(p, :γ)::Any
│   %4 = (%1 + %2 + %3)::Any
└──      return %4
) => Any

julia> @macroexpand SimpleUnPack.@unpack α, β, γ = p
:((; α, β, γ) = p)
1 Like