Planck Static Function Dispatch
Support has landed in Planck for the
:static-fns compiler option. And generally, this option has landed in the compiler for all self-hosted environments: it is a new key-value pair supported in the
opts parameter passed into the various
What does it actually do? Assume you have a ClojureScript function
(defn foo [a b] (+ a b))
that is called like this:
(foo 1 2)
and with it set to
true you will get
Why the difference, and what are the consequences? David Nolen elucidated it:
It's an option mostly because of REPL development to allow for redefinition. For example if
:static-fns truewe statically dispatch to specific fn arities—but what if you redef to a different set of arities? What if you change the var to store a
deftypeinstance that implements
IFn. That kind of thing.
So for compilation
:static-fnscan nearly always be
true, but for the REPL it's not desirable.
In short, enabling it can lead to performance benefits, being more amenable to inlining, etc., but usually you want to leave it turned off during dev.
This new capability can be enabled by passing
--static-fns on the command line when launching Planck.