Speed up a slow loop
Mark Waddingham
mark at livecode.com
Thu Mar 3 01:53:54 EST 2022
On 2022-03-02 21:57, J. Landman Gay via use-livecode wrote:
> 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.
If the difference between `the milliseconds` before the loop, and then
after is 0 or 1 millisecond - then that is how long it is taking. This
means the issue is somewhere else. Are you sure there isn't anything you
are doing either before that loop or after that loop which doesn't wait
for ages (due to the ANRs you mentioned).
> 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.
If there are only 3 reasonable length words in pList (I.e. 3 lines) then
there's no way that loop can take 4 seconds. Of course if the words are
multiple megabytes long then it might be possible (however the timing
you already stated above suggests the loop isn't actually taking 4
seconds!).
> 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.
This strongly suggests it is something else either on your phone, or in
your code which your phone doesn't like I think.
Warmst Regards,
Mark.
--
Mark Waddingham ~ mark at livecode.com ~ http://www.livecode.com/
LiveCode: Everyone can create apps
More information about the use-livecode
mailing list