Thanks, that seems to be the way. But I just made a stress test and found no improvement, CPU usage is the same. I set an instance variable for the sprites and a global variable for keeping track of checked groups. On sprite creation, I set the instance variable to the global and increment the global (from 0 to 2, so I got 3 groups of sprites). In the loop I filter the selected sprite to check with condition (if instance variable match the actual global) and increment the global. Before I tested every 0.6 seconds, now 0.2 with 3 times less calculation per loop.
So it does not lower the total amount of calculations needed of course, but only better divide the amount during same time as before. It only decreases little stuttering that can occur when there is too much calculation in one big loop, by doing more smaller loops.
Very good in theory, but few results in practice.
Do you know other kind of optimization when it comes to large number of units ?