Speed up a slow loop

Jerry Jensen jerry at jhjensen.com
Wed Mar 2 21:02:09 EST 2022


Arrgh.
Try again.

“among the keys of C” 
instead of the keys of tCorrWdList like I wrote.
I’ll quit now.
.Jerry

> On Mar 2, 2022, at 5:44 PM, Jerry Jensen via use-livecode <use-livecode at lists.runrev.com> wrote:
> 
> Now that I’m thinking more directly, I’ll try again:
> 
> Instead of putting the keys OF C into tCorrWdList and using 
> “among the lines of tCorrWdList",
> how about using “among the keys of tCorrWdList”? — wrong - should have geen the keys of C instead
> 
> Judging from no knowledge of the internals but guessing what it must do: 
> “among the lines” has to look for all the line endings (unicode!), 
> but “among the keys” can jump along by constant offsets since
> the keys are all fixed length hashes ?
> The lines happen to be all the same length, but “among the lines” can’t assume that and has to go look.
> 
> Maybe I’m missing something again . . .
> .Jerry
> 
> 
>> On Mar 2, 2022, at 4:19 PM, Jerry Jensen via use-livecode <use-livecode at lists.runrev.com> wrote:
>> 
>> Could using “is among the keys of sDictFile” instead of the loop be another advantage?
>> .Jerry
>> 
>>> On Mar 2, 2022, at 3:12 PM, Devin Asay via use-livecode <use-livecode at lists.runrev.com> wrote:
>>> 
>>> Jacque,
>>> 
>>> Have you tried
>>> 
>>> put the keys of C into tCorrWdList
>>> repeat for each line I in pList
>>> if I is among the lines of tCorrWdList then
>>>    put I & cr after tCheckedList
>>> else
>>>    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:
>>> http://lists.runrev.com/mailman/listinfo/use-livecode
>>> 
>>> Devin Asay
>>> Office of Digital Humanities
>>> Brigham Young University
>>> 
>>> _______________________________________________
>>> 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
>>> 
>> 
>> 
>> _______________________________________________
>> 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
> 
> 
> _______________________________________________
> 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