
3D Game Performance at Startup
Posted Friday, 30 April, 2010 - 20:46 by Stevo14 inHi,
I'm having some problems with performance during the first 10-15 seconds that my game starts running.
In my game scene class I have a List (nautically-themed game) which stores all of the boats in the game. The Boat class contains the boat's state information, physics information (using Tao.ode), and a mesh for rendering. When the boat list has only one boat in it, everything runs fine. I get about 120 fps right from the start of the game. When there are two boats in the list the game runs at < 5 fps for about the first ten seconds, after which it returns to a normal ~100 fps. When I put three boats in the list the situation gets even worse, < 5 fps for at least 15 seconds after the game starts. I assume that the pattern would continue for larger lists of boats (which I would eventually like to have in the game).
My first thought was that the GC was somehow taking a hit so I eliminated all calls to new() in the render and update loops but this didn't help. Somehow I still think the GC is involved, mainly because the problem gets worse with increasing memory requirements. What I really can't understand though is why the problem "fixes itself" after a certain period of time.
Also, the drop in fps is only in the render loop. The update loop actually gets faster when the render fps drops.
Thanks in advance!
(Off topic: It's been a while since I looked around here and I'm glad to see that the OpenTK community is active and growing! :) )


Comments
Re: 3D Game Performance at Startup
Hi! Did you try to profile your app? With your apss's session statistics on hands, you definetly can locate function which takes most CPU cycles as well.
Re: 3D Game Performance at Startup
I tried your suggestion using the built-in mono profiler and found some slow spots which I fixed up. Unfortunately, this didn't fix the problem.
Re: 3D Game Performance at Startup
Have you read this: http://www.mono-project.com/Performance_Tips? Has some useful performance advice.
My guess is that this is a GC issue. Mono doesn't use a generational GC yet, so it is much more sensitive to memory pressure. In general, advice meant for XNA/Xbox360 applies directly to Mono. This is a very useful post on this topic: http://blogs.msdn.com/shawnhar/archive/2007/07/02/twin-paths-to-garbage-...
One other thing to test is whether ahead-of-time compilation can help with this issue:
You can also check memory statistics using:
mono --profile=default:alloc program.exeRe: 3D Game Performance at Startup
I read the blog post that you linked to and one thing really stood out to me:
Accessing value types via an interface causes them to be boxed.
I do this a lot in my code. I now know that this causes frequent memory allocation and therefore frequent garbage collection. I also singled out my Mesh class as a big memory-eating monster (probably causing frequent garbage collection right after the game loads).
In the end, it looks like its time for major refractoring. :)