Hi
I’ve been working on a little piece of my code, trying to solve some performance issues I was getting. The piece of code updates a list of collisions between objects, and then goes through the objects updating their velocities from the collision, then loops round every object and updates it’s location based on velocity and acceleration.
Updating the collision lists gets run often, and as part of it, it gets a list of all object pairs to check for collisions, then calls the method that does the check for that object pair.
I was seeing issues where the collision update was normally taking around 3ms when I had 200 objects in the scene, but would sometimes pike to as much as 60+ms. No good when I am trying to reach a minimum of 30fps, and I’ve not got the lowest spec hardware, so on my hardware I should be approaching 100 or more. The collisions are only updated if a certain amount of time has passed, so if it’s set at 25ms updates, it will not update until 25ms since the last one, and then will do 1 update, which will effect that frames rendering time. 60ms in the middle of that is unplayable.
Having tried netbeans profiler, I couldn’t find any indication as to what the spike was, so I dumped a large amount of debug to see what methods were taking how long on the laggy frames.
I couldn’t see what was causing it even with this extra debug, all the methods seemed to increase in time when I hit the performance drop.
I happened to try the isolated test on a linux box and there was no issue. I tried a few other vm versions on windows to see if it was a jvm issue. If the problem didn’t exist on linux, it suggested it was not my code. I then thought about getting a webstart version running so that I could ask for testers to see if it was my machine. I replaced System.out with a JTextArea in a noddy application and the performance drop again vanished!. Most odd.
I normally leave my machine on 24x7, but we had a power cut last night, so it got rebooted. This evening, out of curiosity I ran the old application, and all was fine, even dumping to the console. In disbelief, I ran it again, and it was screwed. I closed the console, started a new one, and ran it again, all was fine.
It seems that writing to the console in win xp after the first couple of dozen lines of text, starts to seriusly effect performance when you are worried about methods that are called thousands of times a second.
Has anyone else seen this?. Just trying to see if I am missing something else, or if it really not my code, and just not writing to the console will solve my issues.
Thanks
Endolf