ooh, i wondered how words-with was so fast - my first thought was that
it was bound to be the bottleneck, but when i removed the to-array and
things sped up i figured maybe the jvm was more efficient than i
thought :) laziness takes a bit of getting used to!

m.

On Thu, Nov 26, 2009 at 12:26 AM, ataggart <alex.tagg...@gmail.com> wrote:
> 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

-- 
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