Take the 2-minute tour ×

I'm C++ programmer learning Clojure and have limited experience with Java. Now, I have Clojure program referencing just one functions from a library:

(ns app.main
  (:require [clojure.string :refer [join]))

;; Code using join

In C/C++ linker will eliminate unused functions, so there is no significant overhead to reference single function from a library. What happens in JVM/Clojure world? Is it Clojure-compiler specific or JVM general? Will result binary contain all functions from clojure.string or just used?

share|improve this question
There is no resulting binary. There is a class file generated for each namespace, and I believe the modularity of loading the namespace to ram is on the level of class file (loaded when you require that ns). –  noisesmith Sep 10 '13 at 21:03

1 Answer 1

up vote 1 down vote accepted

In JVM land there is no linker. The JVM handles loading and linking. Everything in Java | Clojure is a shared object, so dead code elimination isn't possible. You never know what is going to get used by the code that loads yours.

In clojure every function gets its own .class file(smallest 'binary' file on the JVM). These get zipped into a JAR file which is the standard unit of distribution(this is about equivalent of a .dll or .so). So only the functions you use will get loaded. However if you are worried about distribution size then you are out of luck or have to manually rip apart JAR files to find the right class files.

share|improve this answer
Thank you, it's a complete answer. I didn't know function is a class. It's likely to be IFn implementation. –  demi Sep 11 '13 at 5:13
@demi clojure.org/compilation Is the best reference I can find on how compliation works. –  stonemetal Sep 11 '13 at 13:58

Your Answer


