Bear in mind that when going from the "slow" to the "fast", you not only removed the repeated calls to to-array, but also removed the overhead of words-with, since the lazy seq returned from the let doesn't get fully realized.
Try changing your "fast" version to: (def update-wlist #(let [w (doall (take 26 (words-with (current- word))))] (. words setListData wlistdata))) My guess is it's not going to be fast anymore. On Nov 25, 8:35 am, Martin DeMello <martindeme...@gmail.com> wrote: > I'm writing a crossword editor that provides a list of suggestions to > fill in the current word. This is displayed in a listbox to the right > of the grid, and every time the cursor is moved, I update it via > > (def update-wlist #(let [w (take 26 (words-with (current-word)))] > (. words setListData (to-array w)))) > > This is slowing my UI down very badly - there is a noticeable lag > between hitting a key and having the cursor move. The bottleneck seems > to be to-array, since replacing it with > > (def update-wlist #(let [w (take 26 (words-with (current-word)))] > (to-array w))) > > is still slow, but dropping down to > > (def wlistdata (to-array (take 26 (words-with "...............")))) > > (def update-wlist #(let [w (take 26 (words-with (current-word)))] > (. words setListData wlistdata))) > > leaves everything running smoothly. Is there a more efficient way to do this? > > This is the definition of words-with: > > (def wordlist (split (slurp "csw.txt") #"\n")) > > (defn words-with [re] > (filter #(re-matches (re-pattern re) %) wordlist)) > > so if there's some equivalent that directly outputs a java array, that > would likely solve my problem. I'm open to all suggestions, though. > > martin -- 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