@theagentd Thanks for the explanation, and the code posted. Duh, I’ve been thinking too much on the surface (more involved with other work) to recall the exact details of this technique which I have used before. I can see where CopyOnWriteArrayList could make a single iteration spike in length relative to the others, especially if we are talking about a huge number of missiles flying around, many of which require updating. The more updating happening, the less useful CopyOnWriteArrayList is.
I’m used to working with multiple threads, have only created this error myself in a concurrent use situation. It is hard for me to imagine this error coming up otherwise. If this is happening in a single-thread scenario, that implies code embedded within the render iteration would be altering the array contents, and that raises all sorts of red flags! Render and game state updating should be better isolated from each other.
I’d still like to see a use case that demonstrates the performance differences. Maybe I can find some time to write a short example like the 1000 missiles scenario and test this both ways. And, add a chart that looks at how big a percentage of the units are born or die each iteration and how this impacts the performance. Clearly, though, if there are entity updates every render cycle, it is not a good solution. But if entity updates are rare, relative to rendering (e.g., a hundred renders between updates) then I would want to test the alternatives.
I don’t know enough about the internals of CopyOnWriteArrayList to know how it impacts GC.
P.S., the idea of having pools of Bullets and swapping used ones in and out seems interesting as well. I’ve used something similar in managing notes for a polyphonic synth, where the total number of notes playing at one time has a fixed limit, and we only want to process active notes in the audio loop.