简体   繁体   English

慢茱莉亚启动时间

[英]Slow Julia Startup Time

I am exploring using Julia as a general purpose scientific computing language (as opposed to python), but it's startup time is pretty sluggish. 我正在探索使用Julia作为通用科学计算语言(而不是python),但它的启动时间非常缓慢。

Is there any way of speeding this up? 有没有办法加速这个?

$ time python -c 'print "Hello"'
Hello

real    0m0.030s
user    0m0.018s
sys 0m0.010s

$ time julia -e 'println("Hello")'
Hello

real    0m4.614s
user    0m4.644s
sys 0m0.116s

ADDENDUM : Here is a quote from one of the Julia authors last year. 附录是朱莉娅去年的一位作者的引用。 Was there some difficulty with this strategy? 这个策略有些困难吗?

Most of Julia is written in itself, then parsed, type-inferred and jitted, so bootstrapping the entire system from scratch takes some 15-20 seconds. Julia的大部分内容都是自己编写的,然后进行解析,类型推断和jitted,因此从头开始引导整个系统大约需要15-20秒。 To make it faster, we have a staged system where we parse, type-infer, and then cache a serialized version of the type-inferred AST in the file sys.ji. 为了加快速度,我们有一个分阶段系统,我们在文件sys.ji中解析,类型推断,然后缓存类型推断AST的序列化版本。 This file is then loaded and used to run the system when you run julia. 然后加载此文件并在运行julia时用于运行系统。 No LLVM code or machine code is cached in sys.ji, however, so all the LLVM jitting still needs to be done every time julia starts up, which therefore takes about 2 seconds. 然而,没有LLVM代码或机器代码缓存在sys.ji中,因此每次julia启动时仍需要完成所有LLVM jitting,因此大约需要2秒钟。

This 2-second startup delay is quite annoying and we have a plan for fixing it. 这2秒的启动延迟非常烦人,我们有一个修复它的计划。 The basic plan is to be able to compile whole Julia programs to binaries: either executables that can be run or .so/.dylib shared libraries that can be called from other programs as though they were simply shared C libraries. 基本计划是能够将整个Julia程序编译为二进制文件:可以运行的可执行文件或.so / .dylib共享库,可以从其他程序调用,就好像它们只是共享的C库一样。 The startup time for a binary will be like any other C program, so the 2-second startup delay will vanish. 二进制文件的启动时间与任何其他C程序一样,因此2秒启动延迟将消失。

Unfortunately Julia currently uses a lot of time to start, so it is almost impossible to use it in a bash script for really small problems. 不幸的是,Julia目前使用了很多时间来启动,所以几乎不可能在bash脚本中使用它来解决真正的小问题。 You will probably get a result that favors julia more with a complicated example that uses loops to do things multiple times, but with 2-4 second head start it requires a large problem to have enough time catch up. 你可能会得到一个更有利于julia的结果,一个复杂的例子使用循环来做多次事情,但是在2-4秒的启动时,需要一个大问题才能有足够的时间赶上。 If the startup time is the most important for your scientific computing, Julia isn't ready yet. 如果启动时间对于您的科学计算来说是最重要的,那么Julia还没有准备好。

An equally unfair comparison is to look at computing fibonacci numbers using the stupid recursive formula. 同样不公平的比较是使用愚蠢的递归公式来计算斐波纳契数。 It gets much much worse if you go above 26. Also notice how compact the Julia version of the code is. 如果你超过26,它会变得更糟。还要注意代码的Julia版本是多么紧凑。

>>> ivarne~/dev/julia$ time julia -e 'fib(x) = x<2?1:fib(x-1)+fib(x-2);println(fib(36))'
24157817

real    0m2.763s
user    0m2.776s
sys     0m0.093s
>>> time python -c $'def fib(x):\n    if x<2: return 1\n    else: return fib(x-1)+ fib(x-2);\nprint fib(36)'
24157817

real    0m8.371s
user    0m8.336s
sys     0m0.025s

As you asked for a way to speed up the problem; 正如你想要一种加速问题的方法; here it is: 这里是:

>>> time echo "Hello"
Hello

real    0m0.000s
user    0m0.000s
sys     0m0.000s

The branch I mentioned in the comment has now been merged and julia is more optimized for startup (and doing nothing), than ever. 我在评论中提到的分支现在已经合并,julia比以往更加优化启动(并且什么都不做)。

$> time julia -e 'println("Hello")'
Hello

real    0m0.622s
user    0m1.013s
sys     0m0.624s

This is now available in the nightly builds, and will be included in the next 0.3 release. 现在可在夜间版本中使用,并将包含在下一个0.3版本中。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM