Fork me on GitHub
#clojure
<
2024-03-17
>
whiterose13:03:25

Is there any difference between using Clojure.var and .invoke inside a Java class to import Clojure methods and doing AOT provided by leiningen and then importing it inside Java? Referring to https://cljdoc.org/d/leiningen/leiningen/2.9.3/doc/polyglot-clojure-java-projects-with-leiningen#interleaving-compilation-steps. The flow looks like 1. Java class uses a Clojure function from the project 2. Then we import the Java class inside another clojure function (Create object and invoke) In Java class, when I am initialising the constructor I'll be setting variable = Clojure.*var*("namespace", "method"). Then calling invoke on the variable. Is there any benefit when I just do precomp option given by leiningen?

whiterose13:03:02

Asking this because, saw a difference in response time. Also traces of reflection in Clojure.var usage but not on AOT when we profiled a service.

Alex Miller (Clojure team)13:03:08

The Clojure has to be compiled at some point, so if not aot then it’s compiled when the namespace is loaded

til 1
Alex Miller (Clojure team)13:03:23

You should also create the var once and reuse, not look it up every time

whiterose13:03:44

The var was being created only once in the constructor of the Java class. Need to profile it again. For now, it looked like AOT benchmarks came out to be better than using var. It'll go live tomorrow 🤞 Thanks for the reply 🙏