Functions are objects implementing the IFn interface. This interface
defines a set of methods named "invoke" which return an object given up
to 21 arguments.  Once the compiler is done emitting any given function,
an IFn object has been created. Def is a general operation which creates
a value and binds it to a var named by the current (*ns*, symbol) pair.
So for defn and an instance of this IFn object is what the bound var
points to. So as an example,

user=> (defn foo [x y] (+ x y 1))
; macroexpanded (def foo (fn* ([x y] (+ x y 1))))
#'user/foo

If you inspect the user namespace, you will find that the symbol foo now
maps to the var #'user/foo. Subsequent textual occurrences of the symbol
foo in this namespace will at compile time be mapped to the var
#'user/foo, and the emitted code will take the var #'user/foo and
dereference it to get an IFn object implementing the foo function which
can be invoked.

As there is overhead associated with dereferencing a var and some code
such as clojure.core/* is expected not to be redefined by users, the
^:static annotation in Clojure 1.3 directed the compiler to emit `public
static invokeStatic` methods in addition to the normal `public invoke`
methods. This allowed potentially hot path functions to statically
invoke each other rather than using var indirection. This static linking
of function calls is how Oxcart achieves the reported 24% speedup, and
the linked direct branch is Rich implementing invokeStatic again,
presumably for Clojure 1.7.

This static linking feature was introduced in Clojure 1.3 and removed in
Clojure 1.4 because as I mentioned in my linked blog post the downside
of static linking is that live development and code redefinition become
harder or impossible. My expectation is that, as 1.7 is projected to
introduce compilation profiles, this problem will be mitigated by
different builds or profiles of Clojure which may enable or disable
static linking in a user visible manner. So for an application
deployment build you may choose [org.clojure/clojure "1.7.0-static"]
which can use ^:static annotations for a speedup while for development
you may use [org.clojure/clojure "1.7.0"] which may ignore ^:static in
exchange for a better REPL experience as Clojure 1.6 and 1.5 do.

Hope this helps,
Reid

On 08/06/2014 11:22 AM, Robin Heggelund Hansen wrote:
> Don't understand the compiler that well. Could you provide a short
> description of what is being done?
>
> kl. 13:05:40 UTC+2 onsdag 6. august 2014 skrev Jozef Wagner følgende:
>
>     See this WIP branch https://github.com/clojure/clojure/tree/direct
>     <https://github.com/clojure/clojure/tree/direct>
>
>     On Wednesday, August 6, 2014 12:54:32 PM UTC+2, Robin Heggelund
>     Hansen wrote:
>
>         Just read this blog post about Oxen
>         
> (http://arrdem.com/2014/08/05/of_oxen,_carts_and_ordering/?utm_source=dlvr.it&utm_medium=twitter
>         
> <http://arrdem.com/2014/08/05/of_oxen,_carts_and_ordering/?utm_source=dlvr.it&utm_medium=twitter>).
>         In it is mentioned that Rich is re-introducing invokeStatic to
>         achieve a possible 10% performance increase for Clojure 1.7.
>
>         I couldn't find any information about this. Anyone know where
>         I can find out more?
>
> -- 
> You received this message because you are subscribed to the Google
> Groups "Clojure" group.
> To post to this group, send email to clojure@googlegroups.com
> Note that posts from new members are moderated - please be patient
> with your first post.
> To unsubscribe from this group, send email to
> clojure+unsubscr...@googlegroups.com
> For more options, visit this group at
> http://groups.google.com/group/clojure?hl=en
> ---
> You received this message because you are subscribed to the Google
> Groups "Clojure" group.
> To unsubscribe from this group and stop receiving emails from it, send
> an email to clojure+unsubscr...@googlegroups.com
> <mailto:clojure+unsubscr...@googlegroups.com>.
> For more options, visit https://groups.google.com/d/optout.

-- 
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en
--- 
You received this message because you are subscribed to the Google Groups 
"Clojure" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to clojure+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to