Monday 28 December 2009

Developer Journal 1

Yesterday I modified some code in my simulation to use display lists. I then profiled my simulation overnight.

The good news is that the simulation does seem to be running more quickly. At the moment, there are three steps in the main loop which are taking up the most time.

The three steps are:

MainLoop()
{
UpdateAgents(); // 37%
UpdateGraphics(); // 34%
UpdateInteractions(); // 24%
}

Looking deeper UpdateAgents():

UpdateAgents() // 37%
- agent.Update() // 36%
- - agent.UpdateBrain() // 35%
- - - brain.Update() // 17%

From this I could tell that updating agent neural networks accounted for 17% of processing time. I'm not sure whether the cost is from using smart pointers and vectors in the neural network or from having so many connections. At this point in time I'm not quite ready to look at this further.

The other thing I could tell as that something was happening inside agent.UpdateBrain() that accounted for 18% of processing time. I'm suspecting that the cost is due to calling glReadPixels() to get information from the screen to be a neural network input or from copying between two arrays.

Now that I've gotten some experience from using smart pointers for arrays, I can skip the array copying step and look for an alternative to glReadPixels().

Looking deeper at UpdateGraphics():

UpdateGraphics() // 34%
- sceneView.Draw() // 4%
- - gscene.Draw() // 4%
- RenderAgentPOV() // 29%
- - DrawAgentPOVWin() // 29%
- - - agent.draw() // 28%
- - - - gscene.Draw() // 27%
- - - - - gstage.Draw() // 31%, includes user window rendering cost
- - - - - - graphicObjList.Draw() // 31%, , includes user window rendering cost
- - - - - - - agent.draw() // 5%
- - - - - - - food.draw() // 3%
- - - - - - - barrier.draw() // 0%
- - - - - - - ground.draw() // 0%

There are a few weird things happening here. Firstly, drawing the user window is seems to be quite expensive. The user window is just one window but it takes up 4% of processing time. This is not a lot but it is strange that drawing 250 agent windows takes up 29% of processing time. Could this be due to the user window being bigger than an agent window? Or is it because of something else? The large cost in graphicObjList.Draw() is suspect.

graphicObjList.Draw() takes up 31% of processing time but drawing agents, food, barriers and the ground costs a lot less than that.

Looking deeper at UpdateInteractions():

UpdateInteractions() // 24%
- TransmitCritComm() // 21%

This indicates that there is something in TransmitCritComm() that is quite costly. The cost is probably due to how I am testing whether agents are close enough to hear each other. For each agent, I go through the all the other agents to see if they are close enough. For 250 agents, this works out to be a lot of of comparisons.

The good thing is that profiling helps confirm that investing time into integrating a spatial data structure is worthwhile.

There are a number of things I'm looking at testing to improve the performance of my simulation. The nice thing is that profiling helps to confirm my hunches about where to invest my resources.

No comments:

Post a Comment