Speed up a slow loop

J. Landman Gay jacque at hyperactivesw.com
Sun Mar 6 01:35:59 EST 2022

On 3/5/22 8:36 PM, Quentin Long via use-livecode wrote:
> When you create a new board:
> -- Make a list of all the letters which *are not* on the board
> -- Filter out any word that contains at least one letter on the "not on this board" list
> -- Use the thus-reduced wordlist for all purposes as long as the board doesn't change
> This would add a bit of overhead to the process of setting up a new board, but if it results in time savings during play, the extra overhead might be worthwhile anyway.

Clever. Why didn't I think of that?

I can create a new board, calculate all letters that don't exist on it, and filter out all 
dictionary words containing them in something like 170 ms. It doesn't impact the setup at all. 
It reduces the dictionary from 171,000+ words to around 20,000 give or take, depending on the 
current board distribution. On one board it reduced it to about 11,000 words.

Combined with Ken's suggestion to use "difference", looking up a list of about 50 words in the 
filtered dictionary reduces the time from 2-4 seconds to about 40 ms. It varies, depending on a 
lot of things, but it's fast enough that you don't notice. That's on my Pixel 5; on the Mac a 
lookup takes 5ms. And I can do it all in LC script.

I love these little speed contests we have here. Thank you.

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

More information about the use-livecode mailing list