On Mar 9, 7:31 am, Chris Perkins <chrisperkin...@gmail.com> wrote: > On Mar 8, 6:59 pm, Timothy Baldridge <tbaldri...@gmail.com> wrote: > > > If in a namespace I bind a var: > > > (def foo 3) > > > And then later on in my program re-bind that var: > > > (def foo 1) > > > Will all parts of my program instantly see that update? How is it > > possible to have any sort performance when we're basically having a > > namespace function lookup for every single function call? > > To reiterate what others have said - referencing something that has > been def'd is a two-hop lookup. The first is to follow the symbol, > through the namespace map, to get the Var instance. This is the part > you are concerned about, but it happens at compile-time, so it's all > good. The second hop is to follow the pointer that's in the Var. This > currently (in 1.2) happens at runtime, but it's pretty cheap (just a > pointer deref, I think). In 1.3, this part too will happen at compile- > time unless the var is specifically marked as :dynamic. >
After writing this, I started to wonder whether I really know what I'm talking about, and it turns out I don't :) I checked the code, and my understanding of what is changing in 1.3 was wrong. It does still do the pointer-deref at runtime - what it doesn't do (for non-dynamic vars) is check to see whether it's thread-bound. So it saves an AtomicBoolean.get(). I wouldn't have thought that would save enough time to be worth it, but I guess maybe it does. - Chris -- 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