cameron <cdor...@gmail.com> writes: > Interesting problem, the slowdown seems to being caused by the reverse > call (actually the calls to conj with a list argument).
Excellent analysis, sir! I think this points things in the right direction. > fast-reverse : map-ms: 3.3, pmap-ms 0.7, speedup 4.97 > list-cons : map-ms: 4.0, pmap-ms 0.7, speedup 6.13 The difference between these two I believe is just jitter. Once `cons` is called on either a list or a vector, the result is a `clojure.lang.Cons` object. > vec-conj : map-ms: 4.0, pmap-ms 1.3, speedup 3.10 For the sub-goal of optimizing `reverse`, I get better times even than for the `cons`-based implementation by using transient vectors: list-cons : map-ms: 4.0, pmap-ms 0.6, speedup 6.42 tvec-conj : map-ms: 0.9, pmap-ms 0.2, speedup 4.10 (defn tvec-conj [coll] (persistent! (reduce conj! (transient []) coll))) > list-conj : map-ms: 10.8, pmap-ms 21.2, speedup 0.51 > clojure-reverse : map-ms: 13.5, pmap-ms 26.8, speedup 0.50 (this is > equivalent to the original code) I add the following: cons-conj : map-ms: 3.3, pmap-ms 16.8, speedup 0.19 (defn cons-conj [coll] (reduce conj (clojure.lang.Cons. (first coll) nil) (rest coll))) I think this is the key, but I don’t understand it. The `cons` function just immediately creates a new `Cons` object. The `conj` function calls the `.cons` method of the collection, and the `.cons` implementation `Cons` inherits from `ASeq` just creates a new `Cons` object! It’s like there’s a lock of some sort sneaking in on the `conj` path. Any thoughts on what that could be? -Marshall -- 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