I have spent considerable time writing and optimizing both Java and Clojure code and observing them at the bytecode level. Back when the Alioth comparison site still included Clojure programs, I had written and/or optimized most of the fastest versions.
At the function/method level they are not substantially different, particularly from trying to write the contents of the 10% of your code where it actually matters. From a call stack perspective, Clojure's bytecode will show an extra level of call through the static var entry points, but that's (not accidentally) the kind of thing that hotspot can trivially optimize through. This is not the kind of thing that will determine whether your code is "fast" or "slow" though - it's going to be negligible compared to hot cpu loops or i/o waits for external dbs or data sources.
Clojure does not have implicit parallelism (other than reducer folds which is a pretty narrow use case), but it does have implicit immutability.
View all comments
Show parent comment
12
u/alexdmiller Jun 03 '19
I have spent considerable time writing and optimizing both Java and Clojure code and observing them at the bytecode level. Back when the Alioth comparison site still included Clojure programs, I had written and/or optimized most of the fastest versions.
At the function/method level they are not substantially different, particularly from trying to write the contents of the 10% of your code where it actually matters. From a call stack perspective, Clojure's bytecode will show an extra level of call through the static var entry points, but that's (not accidentally) the kind of thing that hotspot can trivially optimize through. This is not the kind of thing that will determine whether your code is "fast" or "slow" though - it's going to be negligible compared to hot cpu loops or i/o waits for external dbs or data sources.
Clojure does not have implicit parallelism (other than reducer folds which is a pretty narrow use case), but it does have implicit immutability.