On Thu, Jun 11, 2009 at 8:48 PM, Stephen C. Gilardi<squee...@mac.com> wrote: > > > Do you think there will be any performance hits. > > I haven't run any tools on it. In looking around the reflection-related code > in clojure.lang, it looks to me like the performance of new-by-name should > be similar to that of other Clojure code that uses reflection rather than > direct calls.
I think that's correct. In my experience a call that requires runtime reflection like this is on the order of 50 times slower than a method call that is made directly. Depending on how often it gets called, I think that would generally count as a "performance hit". Another option you could consider: moving all code that requires that class into a separate .clj file, then using 'load' when you need it. This would allow you to AOT compile (or not) and suffer none of the runtime reflection cost. Yet another option would be to eval a constructor function. Something like: (defn make-foo [arg1 arg2] (eval `(defn ~'make-foo [a1# a2#] (Foo. a1# a2#))) (make-foo arg1 arg2)) Note that's not well tested. I'm not sure, but you may have trouble elsewhere if you try to type-hint Foo. But basically, that defines a make-foo such that the first time it's called it compiles a new make-foo that will actually create instances of Foo. This will be slow, but subsequent calls to make-foo should run at full compiled speed. Both those options may be pretty painful depending on what you're actually doing, so if I were you I'd try new-by-name first and only if you're sure it's too slow would I try another option. --Chouser --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---