On Sat, Jul 4, 2009 at 4:50 AM, Nicolas Oury<nicolas.o...@gmail.com> wrote: > Hello, > > after experimenting a bit, it seems that you can get a small gain by putting > things in local variables (25% or so) but not much. > > I looked at the implementation and I was assuming something that is not > true: > aset-double does not compile to JVM instructions for setting the array > directly. > It calls a method setDouble. I think the big difference between Clojure and > java comes from that. > When you write r[i] = ... in java, I believe it is compiled to not much more > than a few bytecode instructions to arrange the stack and > one to store in an array. > > When we do the same in Clojure, we call a function that call a method, that > does that. As setting an array is very quick, even the slight overhead of > calling a method makes the program far slower, in a tight loop. > > I will start another thread to ask whether this is really the problem and if > it can be solved. >
With -server, HotSpot inlines the calls to static methods generated by aset on arrays of primitives to the exact same machine instructions. People that want to match the performance of Java on arrays of primitives need to follow the advice given here carefully: http://clojure.org/java_interop#primitives http://clojure.org/java_interop#optimization In particular, aget/aset are overloaded for arrays of primitives. aset-xxx are not. Rich --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---