Reputation: 5504
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
(:gen-class)
(: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?
Upvotes: 0
Views: 101
Reputation: 6208
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.
Upvotes: 1