为什么julia需要很长时间才能导入软件包? [英] Why julia takes long time to import a package?

查看:82
本文介绍了为什么julia需要很长时间才能导入软件包?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我非常担心表现.因此,我将其创建为与第一次调用或导入程序包时的延迟有关的问题.这可能是一个愚蠢的问题.

I am quite concern about performance. So, I am creating this as a question regarding the latency while calling or importing a package at first time. It might be a silly question.

当我第一次添加ex的软件包时,Plots会花费一些时间来构建软件包. 同样,当我第一次在笔记本上导入软件包时,这也花费了一些时间(〜1分钟),提示Precompiling message 导入软件包后,当我点击plot()时,这也要花费一些时间(30s-60s),最后返回绘图.

When the first time I add package for ex, Plots, it consumes some amount of time to build the package. Again when i import the package first time ever on my notebook that also took some time (~1 min) says Precompiling message After importing the package, when I hit plot() this also consumes some time (30s - 60s) and finally returns a plot.

一旦使用了绘图功能,下次使用它就不会花费很多时间来产生结果.

Once I used plot function, whenever I use next time it's not taking much time to produce result.

每当我重新启动笔记本电脑时就会发生这种延迟.

This latency happens whenever I restart a notebook.

我猜想它是在执行之前编译的函数.因为与python不同,julia不是脚本语言.因此,它应该进行编译.但是,为什么每次重新启动笔记本电脑时都会出现延迟?

I guess it's compiling functions before execution. Because unlike python, julia is not a scripting language. So, it supposed to undergo compilation. But, Why the latency occurs every time when I restart notebook?

无论如何,我可以抑制这种延迟吗? 无论如何,我可以对所有内容进行一次预编译,以便下次在病房中无需担心在笔记本电脑或Julia终端中重新启动内核就不会看到任何延迟. 为什么会发生延迟?是完全因为编译时间还是要取决于我的机器?

Is there anyway I can suppress this latency? Is there anyway I can precompile everything once so that next time on wards I don't see any latency without worrying about kernal restart in notebook or in Julia Terminal. Why does the latency happen? Is it fully because of compilation time or it depends on my machine?

推荐答案

您可以做两件事来减少延迟:

You can do two things to reduce the latency:

  1. 使用Julia 1.5.0(今天是beta版)-它动态地允许对软件包使用不同的优化级别,并且Plots.jl正在利用它来将首次绘制时间减少一半以上.这的确是一种垂手可得的成果-茱莉亚(Julia)更新.这是我的笔记本电脑上的尺寸:
  1. Use Julia 1.5.0 (beta as of today) - it dynamically allows to use different optimization levels for packages and Plots.jl is making use of that reducing the time-to-first-plot by more than half. This is indeed a low hanging fruit - update the Julia. Here are the measurements on my laptop:

julia> @time using Plots
 16.816181 seconds (14.46 M allocations: 854.353 MiB, 2.31% gc time)

julia> @time Plots.plot(sin.(1:0.25:7))
  4.292128 seconds (4.70 M allocations: 243.866 MiB, 2.01% gc time)
  # this waits another 7s before the plot actually appears on screen

这些时间不是很好,但是可以接受.

Those times are not excellent but acceptable.

  1. 在您的系统映像中构建Plots(有关详细信息,请参见 https://julialang.github.io/PackageCompiler.jl/dev/examples/plots/)
  1. Build Plots into your system image (for details see https://julialang.github.io/PackageCompiler.jl/dev/examples/plots/)

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

这会将您的首次绘制时间减少到半秒以下.还有一个缺点是,Julia解释器(REPL)需要花费400毫秒以上的时间才能启动,并且在启动Julia时需要使用标志--sysimage sys_plots.so(在Windows上为--sysimage sys_plots.dll).预编译包有时也会带来其他警告(例如,每次更新包都需要重新编译等).

This reduces your time-to-first-plot below half second. Has also a disadvantage that the Julia interpreter (REPL) takes 400ms more time to start and you need to use the flag --sysimage sys_plots.so (or --sysimage sys_plots.dll on Windows) when starting Julia. Precompiling packages can sometimes bring other caveats too (e.g. package updating each time requires recompiling etc.).

这篇关于为什么julia需要很长时间才能导入软件包?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆