Configurations.jl Option Type with StaticArrays.jl

For your second example try using a function barrier:

function _main(x)
    sum = x.a .+ x.b
    for i in 1:1000000
        sum = sum .+ x.a .+ x.b
    end
    return x,sum
end

function main()
    xcfg = from_toml(MyStructConfig, "delete.toml")
    x = convert(xcfg)
    return _main(x)[1]
end

I chose to return some more things because I fear that Julia might optimize the calls out.

This way you isolate the typeinstability to main() and the computation inside _main is typestable and will be fast.

2 Likes