16

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.

Community
  • 1
  • 1
Matt W-D
  • 1,605
  • 2
  • 19
  • 22
  • Now there is a branch in the Julialang repository you can check out. https://github.com/JuliaLang/julia/pull/4898. There are probably some issues still remaining, so try at your own risk. It will probably be included in the upcoming 0.3 release. – ivarne Dec 02 '13 at 14:41

2 Answers2

8

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
ivarne
  • 3,753
  • 1
  • 27
  • 31
  • 1
    I'm not sure what the comparison is supposed to prove. The Python version is buggy -- the two versions don't even compute the same number! -- and you could have written `fib = lambda x: 1 if x < 3 else fib(x-1) + fib(x-2)` if you cared about compactness, although usually Python programmers care about correctness and clarity more than characters. – DSM Sep 26 '13 at 14:43
  • I try to show that when you compare performance between Julia and Python, the result is highly dependent on the task you perform. – ivarne Sep 26 '13 at 15:26
  • 2
    I'm not trying to find the most efficient echo ;-P I was just wondering what the state-of-the-art is in reducing the overhead in julia – Matt W-D Sep 26 '13 at 17:19
  • Hi, I'd just like to point out (I'm a Python user) that since if you're going to use Julia you might want to use it in an interactive environment, using Python with IPython you can still summon Cython. You can Cythonize that function on the fly with a minor type declaration (`def fib(int n): return 1 if n <= 2 else fib(n-1) + fib(n-2)`) and achieve (almost?) `C` performance. – marco Jan 05 '15 at 18:08
7

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.

ivarne
  • 3,753
  • 1
  • 27
  • 31
  • ```time julia -e 'println("Hello")' Hello real 1m35.137s user 0m0.328s sys 1m33.604s ``` And i am on julia 0.5.0 And this is a core i3 machine with 16GiB RAM and not a raspberry pi! – Lord Loh. Oct 02 '16 at 05:13
  • Seems like someting is wrong with your julia installation. What os are you using and how did you install julia – ivarne Oct 03 '16 at 21:39
  • I am using ubuntu 16.04.1 LTS. I installed it from the ".tar.gz" file. – Lord Loh. Oct 03 '16 at 22:08
  • That is really strange, and I can't imagine what might cause startup to take one and a half minute. (Except maybe installing it on a network drive over a slow connection.) – ivarne Oct 05 '16 at 13:07
  • Thank you for the reply. This was on my home server (installed and running there - not over the network storage) that remains on round the clock. Those numbers above were consistent across several runs. But, after a reboot I have - `real 0m0.730s user 0m0.208s sys 0m0.332s` – Lord Loh. Oct 05 '16 at 18:46