为什么 julia 需要很长时间才能导入包?

本文介绍了为什么 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(截至今天的测试版)——它动态地允许对包使用不同的优化级别,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 毫秒以上的时间才能启动,并且您需要使用标志 --sysimage sys_plots.so (或 --sysimage sys_plots.dll 在 Windows 上)在启动 Julia 时.预编译包有时也会带来其他警告(例如,每次更新包都需要重新编译等).

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 需要很长时间才能导入包?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,WP2

admin_action_{$_REQUEST[‘action’]}

do_action( "admin_action_{$_REQUEST[‘action’]}" )动作钩子::在发送“Action”请求变量时激发。Action Hook: Fires when an ‘action’ request variable is sent.目录锚点:#说明#源码说明(Description)钩子名称的动态部分$_REQUEST['action']引用从GET或POST请求派生的操作。源码(Source)更新版本源码位置使用被使用2.6.0 wp-admin/admin.php:...

日期:2020-09-02 17:44:16 浏览:1159

admin_footer-{$GLOBALS[‘hook_suffix’]}

do_action( "admin_footer-{$GLOBALS[‘hook_suffix’]}", string $hook_suffix )操作挂钩:在默认页脚脚本之后打印脚本或数据。Action Hook: Print scripts or data after the default footer scripts.目录锚点:#说明#参数#源码说明(Description)钩子名的动态部分,$GLOBALS['hook_suffix']引用当前页的全局钩子后缀。参数(Parameters)参数类...

日期:2020-09-02 17:44:20 浏览:1060

customize_save_{$this->id_data[‘base’]}

do_action( "customize_save_{$this->id_data[‘base’]}", WP_Customize_Setting $this )动作钩子::在调用WP_Customize_Setting::save()方法时激发。Action Hook: Fires when the WP_Customize_Setting::save() method is called.目录锚点:#说明#参数#源码说明(Description)钩子名称的动态部分,$this->id_data...

日期:2020-08-15 15:47:24 浏览:799

customize_value_{$this->id_data[‘base’]}

apply_filters( "customize_value_{$this->id_data[‘base’]}", mixed $default )过滤器::过滤未作为主题模式或选项处理的自定义设置值。Filter Hook: Filter a Customize setting value not handled as a theme_mod or option.目录锚点:#说明#参数#源码说明(Description)钩子名称的动态部分,$this->id_date['base'],指的是设置...

日期:2020-08-15 15:47:24 浏览:885

get_comment_author_url

过滤钩子:过滤评论作者的URL。Filter Hook: Filters the comment author’s URL.目录锚点:#源码源码(Source)更新版本源码位置使用被使用 wp-includes/comment-template.php:32610...

日期:2020-08-10 23:06:14 浏览:925

network_admin_edit_{$_GET[‘action’]}

do_action( "network_admin_edit_{$_GET[‘action’]}" )操作挂钩:启动请求的处理程序操作。Action Hook: Fires the requested handler action.目录锚点:#说明#源码说明(Description)钩子名称的动态部分$u GET['action']引用请求的操作的名称。源码(Source)更新版本源码位置使用被使用3.1.0 wp-admin/network/edit.php:3600...

日期:2020-08-02 09:56:09 浏览:872

network_sites_updated_message_{$_GET[‘updated’]}

apply_filters( "network_sites_updated_message_{$_GET[‘updated’]}", string $msg )筛选器挂钩:在网络管理中筛选特定的非默认站点更新消息。Filter Hook: Filters a specific, non-default site-updated message in the Network admin.目录锚点:#说明#参数#源码说明(Description)钩子名称的动态部分$_GET['updated']引用了非默认的...

日期:2020-08-02 09:56:03 浏览:854

pre_wp_is_site_initialized

过滤器::过滤在访问数据库之前是否初始化站点的检查。Filter Hook: Filters the check for whether a site is initialized before the database is accessed.目录锚点:#源码源码(Source)更新版本源码位置使用被使用 wp-includes/ms-site.php:93910...

日期:2020-07-29 10:15:38 浏览:825

WordPress 的SEO 教学:如何在网站中加入关键字(Meta Keywords)与Meta 描述(Meta Description)?

你想在WordPress 中添加关键字和meta 描述吗?关键字和meta 描述使你能够提高网站的SEO。在本文中,我们将向你展示如何在WordPress 中正确添加关键字和meta 描述。为什么要在WordPress 中添加关键字和Meta 描述?关键字和说明让搜寻引擎更了解您的帖子和页面的内容。关键词是人们寻找您发布的内容时,可能会搜索的重要词语或片语。而Meta Description则是对你的页面和文章的简要描述。如果你想要了解更多关于中继标签的资讯,可以参考Google的说明。Meta 关键字和描...

日期:2020-10-03 21:18:25 浏览:1691

谷歌的SEO是什么

SEO (Search Engine Optimization)中文是搜寻引擎最佳化,意思近于「关键字自然排序」、「网站排名优化」。简言之,SEO是以搜索引擎(如Google、Bing)为曝光媒体的行销手法。例如搜寻「wordpress教学」,会看到本站的「WordPress教学:12个课程…」排行Google第一:关键字:wordpress教学、wordpress课程…若搜寻「网站架设」,则会看到另一个网页排名第1:关键字:网站架设、架站…以上两个网页,每月从搜寻引擎导入自然流量,达2万4千:每月「有机搜...

日期:2020-10-30 17:23:57 浏览:1298