0

I am making a game in Java. The game is seperated into three threads at the moment (A spawner thread, an update thread, and a draw thread) The spawner spawns an enemy that moves towards the player. After about 800 spawn, the game starts to lag (Which is understandable somewhat). The question is should I create seperate threads for each Ai or should I update them all at once in an update Thread (which is the current case). Which one would produce the better performance?

ziggystar
  • 28,410
  • 9
  • 72
  • 124
Tikitaco
  • 69
  • 7

1 Answers1

2

I suggest you have less critical threads than you have CPUS. If you have 800 CPUs, go for lots of threads. If not, I would expect a much smaller pool of threads would be faster.

How much CPU and memory profiling have you done? You can achieve much greater speed ups with performance profiling than you can achieve my using multiple threads.

Peter Lawrey
  • 525,659
  • 79
  • 751
  • 1,130
  • Using a profiler to find the slowness is the best place to start, it may be that threads won't help at all. – TofuBeer Mar 09 '13 at 20:22
  • @TofuBeer When I am asked to look at a system, my first target is to make it 10x faster by measuring a fixing performance problems often this means *reducing* the number of threads they have. – Peter Lawrey Mar 09 '13 at 20:29
  • …especially if you really have 800 cpus with 800² cache-coherency problems as soon as you synchronize anything… – Ralf H Mar 09 '13 at 20:40
  • @RalfH Correct, It is very hard to keep so many CPUs (or threads) running independently. – Peter Lawrey Mar 09 '13 at 20:41