On Wed, Aug 12, 2009 at 3:59 PM, Richard Newman<holyg...@gmail.com> wrote: > >> Is there some reason that the Java JIT is not doing this, with the >> original code using defn, as fast as it works when using defmacro? > > The macro expands into bytecode within the same Java method, rather > than a method invocation. Some method blocks are too big to inline, > and perhaps the JIT doesn't have enough information (or motivation) to > do so. The JIT compiler will only inline certain hotspots where it > predicts a benefit. Switching to a macro forces the issue by avoiding > that runtime analysis altogether. > > It's also possible that more type propagation, or elimination of > boxing (all function parameters are boxed when they cross the function > boundary) is involved. > > I'm sure others will have more to add... >
I may be wrong, but doesn't a typical function invocation involve dereferencing the Var holding the object that implements "IFn" and calling invoke? It seems pretty intuitive to me that this would be difficult to inline by the JIT, there is a little bit of synchronization going on every time a Var is dereferenced. I think this is why a "let local" variable is faster than def'ing a *constant* and referencing it. Methods like AtomicInteger.get start showing up in the profiler when I use *constants* in tight loops at least. Hotspot is notoriously difficult for us to intuit about, so take this all with a grain of salt. --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---