LoginSignup
26
18

More than 3 years have passed since last update.

PackageCompiler.jlでPlotsの呼び出しを高速化する2020年7月版

Last updated at Posted at 2020-07-20

JuliaではPlotsが遅くて、

@time using Plots

 11.756235 seconds (17.73 M allocations: 964.209 MiB, 2.77% gc time)

とかなってしまい、読み込みが遅くてげんなりしてしまいます。

これを解決するためのパッケージとして、PackageCompiler.jlがあります。
しかし、どんどん開発されたせいでQiitaでも他の記事でも色々な情報が混在して混乱してしまいます。
ここでは、2020年7月現在のPackageCompiler.jlを使ったPlotsの高速化について書きます。

なお、
https://julialang.github.io/PackageCompiler.jl/dev/examples/plots/

「PackageCompiler.jl で Makie.jl の呼び出しを速くする」
https://qiita.com/SatoshiTerasaki/items/478f29cf4343364a136f
を参考にさせていただきました。

確認環境

  • Mac OS 10.14.6
  • Julia 1.4.2

解決策

]キーを押して

add PackageCompiler

でPackageCompilerをインストールします。

次に、

using PackageCompiler
create_sysimage(:Plots,sysimage_path="sys_plots.so")

をします。以上です。sys_plots.soというファイルができていると思います。

使い方

Juliaを一度終了させ、もう一度起動してみます。この時、

julia --sysimage=sys_plots.so

とします。
すると、

@time using Plots

0.002958 seconds (796 allocations: 39.406 KiB)

となりました。
速いですね!

常に早くする。

Macの場合、ホームディレクトリにある.bashrcか.bash_profile
を開き、

alias julia='julia --sysimage ~/sys_plots.so'

を追記しておくと、常にPlotsが早くなります。
あるいは、

echo "alias julia='julia --sysimage ~/sys_plots.so'" |cat >> ~/.bash_profile

でも良いはずです。ここで、sys_plots.soはホームディレクトリにおいてあると想定しています。

26
18
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
26
18