interesting... the changes i suggested cause it to get the first 3
values in around 300ms on my machine and dont blow the heap O_o

On Thu, Jan 20, 2011 at 8:38 PM, Ken Wesson <kwess...@gmail.com> wrote:
> My suspicion is that
>
> (lazy-seq ... (map rest seqs))
>
> in closing over seqs causes the heads of the seqs to be held during
> the recur iteration. When the third value is as big as 1533776805, the
> recur iteration is realizing lengthy portions of the seqs downstream.
>
> The problem with this is that the lazy-seq expression that creates the
> closure occurs on one branch of an if and the recur on the other. A
> call that enters the recur therefore doesn't actually instantiate a
> lazy-seq object holding references to those heads.
>
> If the mere presence of the lazy-seq expression in the function makes
> the heads get held even on an execution path that misses the lazy-seq
> expression, then it may qualify as a compiler bug; after the
> expression (map #(if (= (first %) min-value) (rest %) %) seqs) has
> evaluated and recur is about to be done using the return value, the
> local seqs is clearable and therefore IMO should be cleared.
>
> That said, how about this implementation?
>
> (defn equal-values [seqs]
>  (let [no-value (Object.)
>        sentinel (Object.)]
>    (remove #{no-value}
>      (take-while #(not= % sentinel)
>        (map first
>          (iterate
>            (fn [[rslt seqs]]
>              (if (some empty? seqs)
>                [sentinel [nil]]
>                (let [fs (map first seqs)
>                      min-value (apply min fs)]
>                  [(if (apply = fs) (first fs) no-value)
>                   (map #(if (= (first %) min-value) (rest %) %) seqs)])))
>            [no-value seqs]))))))
>
> This takes about a minute on my box to produce the first three values,
> and doesn't blow the heap.
>
> --
> 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

Reply via email to