And the plot thickens: This:
(defn convert-image [#^bytes cpuArray] (let [unchecked-add clojure.core/unchecked-add len (int (count cpuArray))] (loop [i (int 0)] (if (< i len) (let [ b (byte (aget cpuArray i)) g (byte (aget cpuArray (unchecked-add 1 i))) r (byte (aget cpuArray (unchecked-add 2 i))) a (byte (aget cpuArray (unchecked-add 3 i)))] (aset-byte cpuArray i a) (aset-byte cpuArray (unchecked-add 1 i) b) (aset-byte cpuArray (unchecked-add 2 i) g) (aset-byte cpuArray (unchecked-add 3 i) r) (recur (int (unchecked-add i 4)))))))) vs this. (defn convert-image [#^bytes cpuArray] (let [len (java.lang.reflect.Array/getLength cpuArray)] (loop [i (int 0)] (if (< i len) (let [i2 (unchecked-add 1 i) i3 (unchecked-add 2 i) i4 (unchecked-add 3 i) b (byte (aget cpuArray i)) g (byte (aget cpuArray i2)) r (byte (aget cpuArray i3)) a (byte (aget cpuArray i4))] (aset-byte cpuArray i a) (aset-byte cpuArray i2 b) (aset-byte cpuArray i3 g) (aset-byte cpuArray i4 r) (recur (unchecked-add i 4))))))) The first function takes forever; the second MUCH faster. Upon disassembling the byte-code of the two compiled functions, it does seem like the + was not being inlined. Since the method of reassignment doesn't preserve the metadata, this makes sense. However, my new, modified function is still around 20 times slower than the java version :( I still don't understand what's slowing me down, but I'm much happier that I can get within 20x of java instead of 20000x thanks everyone. sincerely, --Robert McIntyre On Fri, Jan 28, 2011 at 1:07 PM, Ken Wesson <kwess...@gmail.com> wrote: > On Fri, Jan 28, 2011 at 12:55 PM, Benny Tsai <benny.t...@gmail.com> wrote: >> It seems that 'unchecked-add' returns a primitive (note that in the >> first version, 'recur' happily accepts the return from 'unchecked-add' >> without coercion), but when 'unchecked-add' is bound to a new name, >> the return gets boxed. >> >> Is this the correct interpretation, or am I missing something? > > It's correct. Clojure's compiler inlines certain functions, including > clojure.core/unchecked-foo and, when the arity is 2, clojure.core/+ -- > but not a bare, un-qualified +, which might (or might not) at runtime > refer to clojure.core/+ or clojure.core/unchecked-add or whatever. > > -- > 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 -- 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