Optimized TList ?

BlitzMax Forums/BlitzMax Programming/Optimized TList ?

Armitage 1982(Posted 2009) [#1]
Hi

I'm currently trying to optimize some part of my game.

I'm using a Mother type for every objects in my game, so I can manage them easily via a Global TList.
Type Mother
   global List:TList ' This List will receive Mother extended Type with the keyword Self
   ...'sub type management
End Type

But in some cases (2 or 3 times per cycle) I need to access to only a certain type of Extended Type.
For Local player:Player = EachIn Player.List
...
next

I suppose this kind of casting is cycling through each objects of the TList.
This global TList will probably receive between 100 and 400 objects.

Is including a TList inside the Extended Type and cycling without casting would represent an interesting gain in performance ?
Type Player
   global subList:TList ' This List will receive the Player object with the keyword Self
   ...'sub type management
End Type

For Local player:Player = EachIn Player.subList
...
next


Thanks


_JIM(Posted 2009) [#2]
Well, depending on the size of the subList, this could be a great gain performance-wise. If your subList is 10-20 objects versus 100-400 in the global list, you are greatly reducing iterations.

However, maybe there's a way to iterate your global list only once and process each item differently based on its extended type?


Armitage 1982(Posted 2009) [#3]
Thanks for your answer another JIM
However, maybe there's a way to iterate your global list only once and process each item differently based on its extended type?


That's what I do for the main processing but there is 2 specials cases were this is impossible.
My first subList would contain 1-4 objects only and my second more likely 1 but a few more is possible.
Let's resume this by 2 versus 100.
But since I don't know how fast is optimized TList I really wonder if this worth it.

I will probably realise a quick stress test and post the result here.


_JIM(Posted 2009) [#4]
I say its worth doing anyway, because the extra RAM usage is very small (2-4 objects) and the speed of iterating through 2 instead of 100 does make a difference.

Maybe you'll move on to 1000+ objects in the main list. You wouldn't want to iterate that whole list thrice :)

If you're thinking if time consumed to do this vs speed improvement is not worth it, I say it is. Just for the sake of a flexible design that would be optimized even when the numbers change.


Armitage 1982(Posted 2009) [#5]
You right
Plus I did a quick test and that kind of iteration is taking more time because of the casting than cycling directly through the list.
By using a simplest sub list the gain is approximatively a millisecond every game second.
Worth it.

Thanks to share your advices on this ;)