Skip to end of metadata
Go to start of metadata

The problem

Starting a Clojure program takes time to load and initialize the Clojure runtime. Most of this time is taken in loading and initializing vars, largely functions (see Why is Clojure bootstrapping so slow? - from 2014). The time is spent in classloading the function under the var, loading metadata from the constant pool, and initializing the vars.

Many of these vars are not actually needed to start a program - clojure.core in Clojure1.8 has 725 interned vars but a large number of them are unused for most programs at startup time. Delaying the loading of these vars until they are needed would yield significant performance gains. 

Lazy vars

Some work has been done in the (now out of date) "fastload" branch of clojure. The idea is that instead of loading the fn under a var, to instead leave a thunk that can be invoked to load the function when (if) it's invoked. This requires an additional (volatile) check during invocation to determine whether the function has been loading. Performance tests have shown this to impact the ability of the JIT to inline as much as it can without it. 

Patch resurrected from that branch is attached.