Speed up a slow loop

Rick Harrison harrison at all-auctions.com
Wed Mar 2 18:06:54 EST 2022


What happens if you wait longer than 0?

Rick

> On Mar 2, 2022, at 4:57 PM, J. Landman Gay via use-livecode <use-livecode at lists.runrev.com> wrote:
> 
> In my Boggle game I have an array containing dictionary words as keys, split as set, so all values are "true". I need to compare those keys with a list of user words and get back a list of good words and a list of illegal words.
> 
> The loop takes forever. Here it is (sDictFile is a script local):
> 
>  repeat for each line l in pList -- pList is the user word list
>    if sDictFile[l] = true then put l & cr after tCheckedList
>    else put l & cr after tNonWords
>    wait 0 with messages  -- prevent ANRs
>  end repeat
> 
> I added the wait because my Android phone was putting up an "app not responding" warning while the loop was running (or just after, hard to tell.) The loop should be much faster than that. When I added some timing checks though, the timer says the loop takes between 0 and 1 millisecond, and yet the wait on screen remains.
> 
> With a 3-word user list, the loop takes 4 seconds. With an 8 word user list the loop takes 6 seconds. The more user words, the longer the wait.
> 
> Even stranger: on my cheapo Android tablet with 4 megs of RAM running Android 9 the response is nearly instantaneous, even if the user list has 200+ words. On my Pixel phone with 8 megs of RAM and Android 12 the response is slow enough to trigger the ANR with only 3 words. I'm building for ARM 64.
> 
> I've tried any number of workarounds without luck, on both LC 9.6.6 and LC 10.0.0. Any ideas? I have a feeling it isn't the script per se, it's something else.
> 
> -- 
> Jacqueline Landman Gay         |     jacque at hyperactivesw.com
> HyperActive Software           |     http://www.hyperactivesw.com
> 
> _______________________________________________
> use-livecode mailing list
> use-livecode at lists.runrev.com
> Please visit this url to subscribe, unsubscribe and manage your subscription preferences:
> http://lists.runrev.com/mailman/listinfo/use-livecode




More information about the use-livecode mailing list