The best document explaining Julia's design with respect to performance is this paper <http://arxiv.org/pdf/1209.5145v1.pdf>. We're also working on another paper that will be more approachable, especially for those with backgrounds in numerical computing. Julia's speed is not due to any one thing, but to the interaction of a number of its features:
1. an expressive parametric type system, allowing optional type annotation 2. multiple dispatch using type annotations to select implementations 3. dataflow type inference, allowing most expressions to be concretely typed 4. careful design of the language and standard library to allow analysis 5. aggressive code specialization on run-time types 6. just-in-time compilation (using LLVM). Several of these would be hard to introduce into an existing language like R. For example, you could do aggressive type specialization and just-in-time compilation for R, but since R and its libraries weren't designed to make inference effective or easy, it would be difficult to do and might not be as effective as it is in Julia. Many of R's semantics – like lazy evaluation and allowing all values to be NA (including integers) – make efficient implementation challenging. The paper "Evaluating the Design of the R Language <http://r.cs.purdue.edu/pub/ecoop12.pdf>" goes through some of the issues that R's design choices cause for its implementation – it's well worth reading. LLVM is great, but it's not magic. Using it does not automatically make a language implementation fast. What LLVM provides is freedom from doing your own native code generation, as well as a number standard low-level optimizations. You still have to generate good LLVM code. The LLVM virtual machine is a typed register machine with an infinite number of write-once registers – it's easier to work with than actual machine code, but not that far removed (which is the whole point). On Sun, Aug 3, 2014 at 6:01 AM, Michael Smith <[email protected]> wrote: > I've been following Julia with great interest (and a lot of respect), but > one thing that I don't fully understand is why it is so fast. > > For example, let's compare it to R, which is mainly written in C (and a > bit of Fortran). On the other hand (according to Wikipedia), Julia's core > is implemented in C and C++ (similar to R), its parser in Scheme, and the > LLVM compiler framework is used for just-in-time generation of machine > code. Scheme is probably *not* the main reason why Julia is so fast, and > whether one uses C or C++ probably does *not* matter much as well (in > terms of speed). > > That leaves LLVM. So what's so special about it? > > If I get R to use LLVM (which is probably not easy, but let's just speak > in hypotheticals), could I also get a speed comparable to Julia? > > Thanks, > M >
