On Mon, Jul 27, 2009 at 3:37 PM, Mark Addleman <mark_addle...@bigfoot.com>wrote:
> > I have written some Clojure code to implement java.lang.CharSequence > that is constructed with a length and an ISeq of strings. I need this > because I want to pass the resulting CharSequence into Java's regex > library. I got the thing working (thanks to the docs and some good > examples that I found in the discussion group) and I'm trying to > optimize it now. I'm willing to accept the Clojure code being ~2x > slower than the Java equivalent, but the best I can do is 10x slower. > > The code is below. After examining the resulting bytecode, it looks > to me that the problem is that the Clojure compiler dispatches every > method to an IFn that is bound as part of the class initialization. > It's a cool idea that probably saved implementation effort but I'm > pretty sure all the boxing/unboxing of primitives is what's killing > the performance. > > My question is: Can someone come up with a better way of implementing > this to avoid the performance problems? The only way to avoid boxing and unboxing of primitives is to avoid passing them as arguments or returning them. It *may* work if you declare the functions inline that need to do so, but you may need to rewrite it in a less functional style using loop/recur. Clojure is capable of the speed you want, though; indeed, even of the speed of hand-tuned assembly, when done right. --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---