Need an idea

I have an array “X” of N objects (where N is about 175) amongst other attributes, each has a boolean flag value
Each time the user performs an operation (key, mouse etc) various other objects change state (for example a text string changes)
then based on a number of criteria between 0 and 50 of those first mentioned objects set to false (and all others are reset to true if required)

What I am trying to figure out is the fastest way to do this.
Array “X” never changes in size once the app starts
the number of items in Array “X” that need to be set to false is very dynamic, and needs to be updated whenever the user performs a key or mouse down action

my current method is to create a dynamic array “Y” of all the “X” items tags that need to be set to false and then do something like

//  code goes here to create "Y" based on time specific criteria
for i = 0 to X.ubound
for j=0 to Y.ubound
if Y(j)=X(i).tag then x(i).flag=false
next j
next i

while that works, it is very slow and the lag is perceptible to the user

The unfortunate thing is that “X” may have up to 5 items all with the same tag value and their position within “X” is not ordered
I thought about using a Dictionary, but that requires a unique “key” so I can’t have 5 items tagged the same (and those tag values have meaning elsewhere in the app)

Another idea was to set the flag as each criteria was checked, but that took the same amount of time, just spread it out more

the only other idea I have is to leave “X” an array, and make “Y” a dictionary,

for i=0 to X.Ubound
 X(i).flag=NOT (y.hasKey(x(i).tag))
next i

Anyone have any better ideas???

Could you use indexof to check if x(i).tag exists in the y array?

If Y.IndexOf(x(i).tag) > -1 then x(i).flag = false

Don’t know what the speed improvement would be though.

Have you tried disabling background tasks during the loop? I did that with a similar mechanic and saw an amazing reduction in time.

This honestly sounds like a good use for an in-memory sqlite database.

a dictionary would probably be as fast

not sure that the overhead would be worth it for <200 “records”

You’re looking for performance, right? That’s exactly what taking on extra memory overhead is about. You could update the desired records far, far faster with sqlite than you can with xojo. The question really is wether or not that saved time wouldn’t be lost getting objects into and out of the database. That really comes down to how your application is setup.

Tag is a variant.
Conversion between types (even if not obviously needed) may be causing some slowdown here.
Could you use subclasses with a text attribute instead of using .tag?

actually the most time was the comparison of two arrays… by converting to a dictionary and only making one pass it reduced the time to an acceptable level…