- I’ve updated the Dockerfile above by adding keyword argumnet
precompile_execution_file
.
It will improve performance.
See https://julialang.github.io/PackageCompiler.jl/dev/examples/plots/ fore more information.
FROM terasakisatoshi/jlcross:rpizero-v1.4.2
RUN julia -e 'using Pkg; \
Pkg.add(["PackageCompiler", "StaticArrays"]); \
# precompile pacakges; \
using PackageCompiler, StaticArrays'
RUN mkdir /sysimages
RUN echo 'using StaticArrays; s1=SVector{3}(0.0,0.0,0.0); s2=SVector{3}(rand(3)...); s1+s2' >> /home/pi/executionfile.jl
RUN julia /home/pi/executionfile.jl
RUN julia -e '\
using PackageCompiler; \
import PackageCompiler:march, default_app_cpu_target; \
# To specialize in Raspberry Pi zero, \
# we will override `march` and `default_app_cpu_target` \
march()=nothing; \
default_app_cpu_target() = "arm1176jzf-s"; \
create_sysimage([:StaticArrays], precompile_execution_file="/home/pi/executionfile.jl", sysimage_path="/sysimages/sarrays.so"); \
'
RUN julia -e '\
@time using StaticArrays; \
@time s1=SVector{3}(rand(3)...); \
@time s2=SVector{3}(rand(3)...); \
@time s1+s2;\
'
RUN julia -J/sysimages/sarrays.so -e '\
@time using StaticArrays; \
@time s1=SVector{3}(rand(3)...); \
@time s2=SVector{3}(rand(3)...); \
@time s1+s2;\
'
$ docker build -t sample .
will output …
...
...
...
Step 7/8 : RUN julia -e '@time using StaticArrays; @time s1=SVector{3}(rand(3)...); @time s2=SVector{3}(rand(3)...); @time s1+s2;'
---> Running in 04803b0cf08e
8.666841 seconds (2.63 M allocations: 97.241 MiB)
4.802351 seconds (527.82 k allocations: 23.474 MiB, 0.66% gc time)
0.000365 seconds (6 allocations: 224 bytes)
2.840873 seconds (275.62 k allocations: 10.468 MiB, 0.30% gc time)
Removing intermediate container 04803b0cf08e
---> d272f875c9e9
Step 8/8 : RUN julia -J/sysimages/sarrays.so -e '@time using StaticArrays; @time s1=SVector{3}(rand(3)...); @time s2=SVector{3}(rand(3)...); @time s1+s2;'
---> Running in 9b1244590691
0.014529 seconds (528 allocations: 17.688 KiB)
0.242853 seconds (253 allocations: 32.297 KiB)
0.000339 seconds (6 allocations: 224 bytes)
0.000107 seconds (1 allocation: 32 bytes)
Removing intermediate container 9b1244590691
---> d0b825ef3d9d
Successfully built d0b825ef3d9d