Creating a small object like that is cheap on the JVM.  There are much
better places to put optimization effort.

On Wed, Feb 18, 2009 at 1:07 PM, Michel Salim <michel.syl...@gmail.com>wrote:

>
>
>
> On Feb 18, 3:17 am, Laurent PETIT <laurent.pe...@gmail.com> wrote:
> > Hello,
> >
> > 2009/2/18 CuppoJava <patrickli_2...@hotmail.com>
> >
> >
> >
> > > Hi,
> > > I've noticed that I'm creating a lot of maps of functions, and I'm
> > > wondering if there's a performance penalty for this.
> >
> > > ie.
> > > (defn create_fn []
> > >  (fn [] (println "hi")))
> >
> > If you use AOT compilation, you'll see that this code will add 2 new
> classes
> > to the namespace it is declared in : one class for create_fn itself, and
> one
> > anonymous class for (fn [] (println "hi"))
> >
> > > ((create_fn))   <--- Does this "create" a new function every-time it's
> > > called? Or is the function code cached somewhere? How much of a
> > > performance penalty does this incur?
> >
> > Each call to create_fn will create a new instance (object) of the
> anonymous
> > class for (fn [] (println "hi"))
> >
> Is this something that will eventually be optimized? This anonymous
> function does not capture any variable, and therefore can just be
> instantiated once.
>
> Regards,
>
> --
> Michel S.
> >
>

--~--~---------~--~----~------------~-------~--~----~
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
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
-~----------~----~----~----~------~----~------~--~---

Reply via email to