time java -client -jar clojure.jar helloworld.clj
> system time 0.0001s
The -client param makes all the difference :)
time java -client -jar clojure.jar helloworld.clj
> system time 0.0001s
The -client param makes all the difference :)
And to save folks a click:
> The Client VM compiler does not try to execute many of the more complex optimizations performed by the compiler in the Server VM, but in exchange, it requires less time to analyze and compile a piece of code. This means the Client VM can start up faster and requires a smaller memory footprint.
There's literally so many just insane things about the JVM and its variants, I totally get why some folks are like "JAVA OR DEATH." I just wish I had started learning it 20 years ago, like a lot of 'em, so it wasn't such a gigantic wall of pedantic knowledge to acquire.
Why is there no magical --client / --script option for the Clojure ClI to make startup faster, if this is such an easy solution? Also, you show system time, but the time to load dependencies is in user time, which is slow by the nature of Clojure.
Example:
$ time java -client -classpath /usr/local/Cellar/clojure /1.10.1.492/libexec/clojure-tools-1.10.1.492.jar clojure.main hello.clj
Hello, world
java -client -classpath clojure.main scripts/script.clj 1.39s user 0.08s system 187% cpu 0.788 total
$ time java -classpath /usr/local/Cellar/clojure/1.10.1.492/libexec/clojure-tools-1.10.1.492.jar clojure.main hello.clj
Hello, world
java -classpath clojure.main scripts/script.clj 1.37s user 0.09s system 180% cpu 0.811 total
(Excuse the details of my Clojure install location above)User time appears slightly slower without the -client option, but probably is not statistically significant. Also, anyone who has worked on more than a toy project with Clojure knows that it's not just about the Hello World startup speed, every dependency you add has a significant impact on Clojure startup time.
IIRC Clojure apps are slow to start because they do a lot of first-time setup work that isn't actually executing user code. It's not so much a JVM problem as a Clojure-emitted-code problem. The GraalVM native-image tool fixes it because it can start an app in a pre-initialised state.
In other words, if Rich' example is real and recent, what could possibly be the environment in which this worked?
> As it turns out, Clojure start time is a complicated and multi-dimensional topic. Clojure projects are slow to start not only because of JVM — JVM itself starts in ~50 ms — but because of JVM specifics the classes are loaded slowly. Clojure projects are slow to start not only because of Clojure — Clojure itself starts in ~1 second — but because of Clojure specifics, the namespaces, especially not AOT-compiled one, are loaded slowly. And so on.
With and without -client 1 second
Built with graal 22 ms