Slow Julia Startup Time

2019-04-21 02:36发布

I am exploring using Julia as a general purpose scientific computing language (as opposed to python), but it's startup time is pretty sluggish.

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. 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. This file is then loaded and used to run the system when you run 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.

This 2-second startup delay is quite annoying and we have a plan for fixing it. 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. The startup time for a binary will be like any other C program, so the 2-second startup delay will vanish.

2条回答
Deceive 欺骗
2楼-- · 2019-04-21 03:04

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. 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. If the startup time is the most important for your scientific computing, Julia isn't ready yet.

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.

>>> 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
查看更多
霸刀☆藐视天下
3楼-- · 2019-04-21 03:23

The branch I mentioned in the comment has now been merged and julia is more optimized for startup (and doing nothing), than ever.

$> 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.

查看更多
登录 后发表回答