Speed up a slow loop

J. Landman Gay jacque at hyperactivesw.com
Thu Mar 3 01:27:49 EST 2022


On 3/2/22 11:41 PM, Richard Gaskin via use-livecode wrote:
> Jacque wrote:
> 
>  > so I'm not really looping through the keys, just looking for
>  > a matching one. The loop is for each user word I need to find.
>  > If there's no key, then the word isn't legal.
> 
> What is the ratio of keys whose values are "true" and those which are "false"?

There are no false values. The list of words is split as a set, so the keys are the dictionary 
words and all values are true.

> And what is the ratio of writes to that array vs reads?

No writes at all, read only. The dictionary is stored gzipped as a custom property. On launch 
it is decompressed, split into an array, and stored in a script local. It's about 1.8 MB 
decompressed, I think. Maybe the array structure adds a bit. Not huge, but not small either. 
The SOWPODS dictionary was twice that size, but my puny tablet had no problem with it.

When the user submits a list of words, the handler sees if the array[userWord] is true. I used 
to just see if the value was empty, but either way it works the same. If no key is available, 
the word is illegal.

BTW, there's another place with a similar slowdown, but one thing at a time. As before, this 
second thing works fine on the tablet but is slow on my phone. Maybe the reason is the same.

-- 
Jacqueline Landman Gay         |     jacque at hyperactivesw.com
HyperActive Software           |     http://www.hyperactivesw.com



More information about the use-livecode mailing list