GraalVM

To install the native-image compiler, you need to use gu, a tool for updating Graal.

For GraalVM Community Edition users, install a component from the GitHub catalog by its name gu install native-image. After this additional step, the native-image executable will become available in the bin directory, as for the previous releases.

Resources

  • Debugging javax.xml.bind.DatatypeConverter when building for Linux.

  • A GraalVM web example with Clojure

  • Getting Java/Clojure to talk to Rust / Other languages - Example Repo

  • See the section below on type hinting

  • Reading compile scripts / options on existing codebases: Sci and Babashka

Type Hinting

I often forget how to type-hint different forms in Clojure. I usually only end up doing this when using GraalVM.


;; Type hinting the let binding
(let [^String s (something-returning-a-string)]
  (.isEmpty s))

;; Type hinting a function parameter
(defn empty? [^String s]
  (.isEmpty s))

;; Type hinting a Java Interop method call.
(.isEmpty ^String (something-returning-a-string))

;; Type hinting a return value on a function
(defn ^String myfn []
  "I'm a string")

;; A multi arity type function return
(defn myfn2
  (^String [] "I'm a string")
  (^String [a b] "I'm a string too"))

src: Performance nemesis: reflection - Clojure Goes Fast