Taking advantage of pkgimages in 'scripts'

It’d be nice if we had a way to build “scriptimages” which were just a wrapper around a pkgimage that could be invoked by julia from the command line in a similar way to a script.


For what it’s worth, I just tried taking the above linked script and shoved it in a little dev’d package, removed the interactive part and added

function main(N = parse(Int, ARGS[1]); bodies=bodies)
    @printf("%.9f\n", energy(bodies))
    nbody!(bodies, N)
    @printf("%.9f\n", energy(bodies))
end

using SnoopPrecompile

# This will let SnoopPrecompile AOT compile all the machine code we need to just call `main()` from a script.
@precompile_setup begin
    _bodies = copy(bodies)
    @precompile_all_calls begin
        push!(_bodies, init_sun(_bodies))
        main(1000; bodies=_bodies)
    end
end

The timings I got on my machine using the original script was

real    0m2.453s
user    0m2.343s
sys     0m0.698s

and now using the precompiled pkgimage to invoke main() I get

real    0m1.982s
user    0m2.069s
sys     0m0.697s

So almost a 20% speedup of the wall time. If they got a 20% wall time speedup in the benchmarks posted: n-body (Benchmarks Game) julia would actually be the fastest language shown.