Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

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.

like image 489
Matt W-D Avatar asked Sep 25 '13 16:09

Matt W-D


1 Answers

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
like image 181
ivarne Avatar answered Oct 26 '22 05:10

ivarne