Speed up a slow loop

Devin Asay devin_asay at byu.edu
Wed Mar 2 18:12:49 EST 2022


Have you tried

put the keys of sDictFile into tCorrWdList
repeat for each line I in pList
   if I is among the lines of tCorrWdList then
      put I & cr after tCheckedList
      put I & cr after tNonWords
   end if
end repeat

I just wonder if there is some overhead with checking the array on each iteration.

But like you say, it may not be the repeat loop at all.

- Devin

On Mar 2, 2022, at 2:57 PM, J. Landman Gay via use-livecode <use-livecode at lists.runrev.com<mailto: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<mailto:jacque at hyperactivesw.com>
HyperActive Software           |     http://www.hyperactivesw.com

use-livecode mailing list
use-livecode at lists.runrev.com<mailto:use-livecode at lists.runrev.com>
Please visit this url to subscribe, unsubscribe and manage your subscription preferences:

Devin Asay
Office of Digital Humanities
Brigham Young University

More information about the use-livecode mailing list