Planck Static Function Dispatch

November 3, 2015

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 cljs.js APIs.




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)

With :static-fns false (the default), the generated JavaScript call will look like

cljs.user.foo.call(null,1,2)

and with it set to true you will get

cljs.user.foo(1,2)

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 true we 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 deftype instance that implements IFn. That kind of thing.

So for compilation :static-fns can 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.

And—importantly for Planck—it can be used to work around a particularly severe JavaScriptCore perf bug that you can encounter when evaluating the JavaScript generated for lengthy literal list forms.

This new capability can be enabled by passing -s or --static-fns on the command line when launching Planck.

Tags: Planck ClojureScript Bootstrap