Speed up a slow loop

Ralph DiMola rdimola at evergreeninfo.net
Wed Mar 2 22:29:43 EST 2022


I ran into this when doing mobile predictive typing for US cities(40,000)
with a scrollable dropdown of results. I did with a loop in JavaScript in
html and was instantly fast. So in LC IDE I started with the loop thing and
it was too slow. There was a 3/4 of a second blip as each character was
typed. I found that "filter the lines" is blazingly fast. So I built the cr
list of cities with the city followed by a dash and then the metadata I
needed (lat/lons). Use the "filter into" form so the original list remains
unchanged. I do a filter for each character typed. Works like a charm. Now
LC is as fast as the JavaScript version. 
When filtering if you want the exact term then search with the dash added at
the end for the search term.

"filter" must be using your time machine somehow.

Ralph DiMola
IT Director
Evergreen Information Services
rdimola at evergreeninfo.net

-----Original Message-----
From: use-livecode [mailto:use-livecode-bounces at lists.runrev.com] On Behalf
Of J. Landman Gay via use-livecode
Sent: Wednesday, March 02, 2022 4:58 PM
To: LiveCode Mailing List
Cc: J. Landman Gay
Subject: Speed up a slow loop

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