The dynamic variable *compiler-options* holds a configuration map for selected Clojure compiler behaviors. Bind it around compilation or evaluation, or supply equivalent -Dclojure.compiler.* command-line properties. section 23.8
The supported options control memory behavior, emitted metadata, and Var dispatch:
- :disable-locals-clearing prevents the compiler from nulling selected local attributes after use, which assists debugging but normally favors production use. section 23.8
- :elide-meta accepts metadata keywords such as :doc or :file and omits them from emitted Java classes, reducing executable size and startup time. section 23.8
- :direct-linking enables calls that bypass the indirection introduced by dereferencing Vars. section 23.8
Inspecting local clearing
Bind {:disable-locals-clearing true} while compiling a form, then decompile the generated classes. With the option enabled, captured local s remains assigned instead of being set to null after use. section 23.8
(binding [*compile-files* true
*compile-path* "."
*compiler-options* {:disable-locals-clearing true}] ; #1
(eval '(let [s "potentially-huge"] (^:once fn* [] s))))
Compile a closure with local clearing disabled, then compare its generated Java with the default output. section 23.8
import clojure.lang.AFunction;
//
// Decompiled by Procyon v0.5.36
//
public final class user$eval35 extends AFunction
{
public static final Object const__1;
public static final Object const__2;
public static Object invokeStatic() {
return user$plus #1
.invokeStatic(user$eval35.const__1,
user$eval35.const__2);
}
public Object invoke() {
return invokeStatic();
}
static {
const__1 = 1L;
const__2 = 2L;
}
}
Compare direct linking with ordinary Var-based invocation in decompiled output. section 23.8
