Why is GraalVM so fast?


#1

Kept seeing updates from GraalVM and my friends talked about that for several times. It made really curious why it can be so fast than JVM and JVM has been optimized for so many years, By fast I’m mean startup speed. Or what features did GraalVM sacrifice that made this optimizations available?


#2

Its my understanding GraalVM is not faster to start, its actually even slower. What is fast is native-image compilation it offers for Java programs.

When the JVM starts, it must first link and compile all the code to machine code. That’s why its called Just in Time compilation.

Native image in Graal VM pre-compiles everything to machine code for a specific platform.

So when you start machine code of your program, all that needs to happen is load the code from disk to ram and call the first instruction. That’s as fast as it gets.

When you start normal Java byte code, it must first compile it, which adds overhead. Then it must load and call the first instruction.


#3

It is not fast unless you use native-image.

You can think of native-image being the :advanced compilation for Clojure. native-image takes all your code and makes a standalone binary out of it that only contains the code that was actually used.

It starts faster after building that native-image, without that its actually really slow at running JS for example…


#4

#5

This is impressive. A bit far from my current Clojure skills, but I would love to learn how to compile small scripts to binary.


#6

I would be interested in a combined approach: native image for Clojure itself so you would have fast startup + scripting on top of that, so you can inspect/alter the source of the script and it’s not a black box once you deliver/deploy the package. Would this be feasible with GraalVM?


#7

Not sure as it currently stands, because Clojure adds new classes to implement functionality (we have a compiler after all) and this is not allowed in Graal images. Still, for a script, it would be pretty cool!


#8

You can use the native-image to build a fast executable image for your clojure application, The startup time is much much faster.