
Command-line apps with Clojure and GraalVM: 300x better startup times - kimi
https://www.astrecipes.net/blog/2018/07/20/cmd-line-apps-with-clojure-and-graalvm/
======
me_again
"So you have no excuses not to build your CLI tools in Clojure now."

Except that the toy program is 25MB and takes multiple minutes to compile...

~~~
kodablah
That and you are using proprietary Oracle tech.

~~~
DannyB2
If you are referring to Java, I would point out:

Oracle's JDK is based on Open JDK.

Open JDK is licensed under GPL + the classpath exception. (eg, the Open JDK is
under GPL, but when used as a runtime for other software, then that other
software does not come under the scope of the GPL.)

There are multiple other sources to get pre-build binaries for the Open JDK
without going to Oracle.

Azul Zule built for multiple platforms including Linux, Mac OS, Windows.

[https://www.azul.com/downloads/zulu/](https://www.azul.com/downloads/zulu/)

And Zulu for Raspberry PI:

[https://www.azul.com/downloads/zulu-
embedded/](https://www.azul.com/downloads/zulu-embedded/)

Open JDK Build:

[https://github.com/ojdkbuild/ojdkbuild](https://github.com/ojdkbuild/ojdkbuild)

(click the 'releases' link)

Adopt Open JDK:

[https://adoptopenjdk.net/index.html](https://adoptopenjdk.net/index.html)

(offers choice of HotSpot or IBM's Open J9 technology)

There's also Red Hat, for free, but you must create an account.

And IBM makes their own builds, but they are typically bundled with some other
product such as Eclipse, so a bigger download.

~~~
kodablah
> If you are referring to Java [...]

I'm not.

~~~
DannyB2
What proprietary Oracle tech are you referring to?

~~~
kodablah
GraalVM. Sorry that wasn't clear from my initial statement.

~~~
akerro
That's GNU GPL 2
[https://github.com/oracle/graal/blob/master/LICENSE](https://github.com/oracle/graal/blob/master/LICENSE)

------
Jeaye
To the author:
[https://www.youtube.com/watch?v=OonDPGwAyfQ](https://www.youtube.com/watch?v=OonDPGwAyfQ)

In other words, thank you for the content, but this could really use some
proofreading.

~~~
prudhvis
Thank You. This is a good video to drive the massage.

~~~
Skunkleton
Nothing like a good massage!

~~~
ofrzeta
related: "Why is the title of the book The Medium is the Massage and not The
Medium is the Message? Actually, the title was a mistake. When the book came
back from the typesetter's, it had on the cover 'Massage' as it still does.
The title was supposed to have read The Medium is the Message but the
typesetter had made an error. When McLuhan saw the typo he exclaimed, 'Leave
it alone! It's great, and right on target!' ..."
[https://en.wikipedia.org/wiki/The_Medium_Is_the_Massage](https://en.wikipedia.org/wiki/The_Medium_Is_the_Massage)

------
87
If you really want to script in Clojure you should probably use Lumo
[https://github.com/anmonteiro/lumo](https://github.com/anmonteiro/lumo) .
Starts up almost instantly (including a repl!). Still wouldn't recommend. But
it's workable.

~~~
kimi
Looked into it, but the big thing of my scripts is that they often use JDBC or
http-kit, so cljs would not be as good.

------
Cthulhu_
Generally speaking, startup times for Java / JVM based apps should be worked
on next by the teams behind it; in the container age, fast startup is a good
thing. I know the JVM itself starts up fast enough, but then going with e.g.
Spring on top of that just adds a minute of startup time - and I've no clue
what it's doing, I wouldn't think loading config, registering services and
opening up a servlet thingy would take so long.

~~~
pmarreck
Long JVM startup time is a big reason why I went with Elixir instead of
Clojure when I decided to move off Ruby to do webdev. (Another reason was
easily triggering nasty Java stacktraces.)

My Elixir test suites fire up instantly and finish in seconds (if that) and
this fast-as-possible feedback loop is _extremely important_ to stay
productive, IMHO.

~~~
pron
Clojure startup time is only partly related to JVM startup time, which is
~60ms[1][2]. The reason Clojure startup is slow is because Clojure requires a
very elaborate initialization. OTOH, the Erlang VM (BEAM) is much, much,
_much_ slower than the JVM (Hotspot, at least).

[1]: [https://blog.ndk.io/clojure-
bootstrapping.html](https://blog.ndk.io/clojure-bootstrapping.html)

[2]: [http://clojure-goes-fast.com/blog/clojures-slow-start/](http://clojure-
goes-fast.com/blog/clojures-slow-start/)

~~~
dman
Cant you just have a system clojure process started up and then fork from
there?

~~~
pron
Forking, in general, is not a very safe operation when the process is an
elaborate one, like a JVM. It may, however, be possible to have Graal compile
the Substrate VM image for Clojure _after_ the initialization has been done,
dumping the initialized state to the image, and then just loading it on
launch. This may be the solution chosen once Graal matures a bit, and people
learn how to use it well.

------
cutler
"6G to 8G RAM" to compile. A real win then.

~~~
thomaswue
This compilation step is only required once when you release your tool. The
resulting binary is then providing fast startup and low memory footprint
whenever users invoke your tool. So, yes, it is a real win if your tool gets
used more than once.

~~~
xfer
Or use like lots of other languages that provide all these "wins" without
having to provide justifications like "only for release build and if your tool
gets used more than once".

~~~
yogthos
I spend most of my time actually programming in the language, not compiling
it. So, I'm going to optimize for that, but to each his own I suppose.

~~~
xfer
It's not an either-or, you can have both.

~~~
yogthos
I can't really think of a language that I'd rather use than Clojure right now.
So, I'd have to get these "wins" I'd have to switch to working with a language
I enjoy less.

------
codedokode
Why cannot Java probuce binaries that can be mapped into memory and shared
like native executable files? It could solve the startup time problem.

Google even had to invent a zygote process in Android to make apps start
faster.

~~~
chrisseaton
> Why cannot Java probuce binaries that can be mapped into memory and shared
> like native executable files? It could solve the startup time problem.

It can. That’s what this article is about.

------
jgh
ah this is great. I need to look at switching to Graal.

~~~
exabrial
Graal can be used as the JIT compiler got your JVM. It's also pretty easy to
hack on. There a great presentation on YouTube by one of the project leads
about that.

