I have enhanced my scripts at the repo I linked before so that some of them print out JVM byte code disassembled listings for the original foo2 function, and the variations that cgrand gave earlier in this channel. I noticed in the JVM byte code that while (let [n (int n)]
caused the local n
to use a Java int
primitive value, the Clojure compiler still chose to use a long
primitive for the loop local i
created from (loop [i (int 0)]
: https://clojure.org/reference/java_interop#primitives
https://github.com/jafingerhut/leeuwenhoek for the updated repo contents.
I do not necessarily think that is the root cause of the performance weirdness -- just something I noticed and thought I would mention here in case it was unexpected.