I've been trying to find & fix various garbage generators and I came across something in Bepu which I would like to understand better.
The profiler pointed me to this callstack as a source of objects being generated & discarded (I don't know why the right edge with more stats is being cut off here, but visit the link directly to see the full pic):
In my contrived situation of just having a weapon fired repeatedly into the ground, this allocation is around 20% of all garbage my app is creating so I'm interested in fixing it if possible.
What is happening in game is a weapon creates a capsule as a slow moving projectile that that is removed from the scene after it hits the ground.
What I find curious is down in EntitySolverUpdatable.UpdateConnectedMembers, I see this bit of code:
Code: Select all
void UpdateConnectedMembers()
{
//Since we're about to change this updateable's connections, make sure the
//simulation islands hear about it. This is NOT thread safe.
var deactivationManager = simulationIslandConnection.DeactivationManager;
if (deactivationManager != null)
{
simulationIslandConnection.Owner = null; //Orphan the simulation island connection.
deactivationManager.Remove(simulationIslandConnection);
}
else if (!simulationIslandConnection.SlatedForRemoval) //If it's not already going to be cleaned up, then we need to do it here.
Resources.GiveBack(simulationIslandConnection); //Well, since we're going to orphan the connection, we'll need to take care of its trash.
//The SimulationIslandConnection is immutable.
//So create a new one!
//Assume we've already dealt with the old connection.
simulationIslandConnection = Resources.GetSimulationIslandConnection();
for (int i = 0; i < involvedEntities.count; i++)
{
simulationIslandConnection.members.Add(involvedEntities.Elements[i].activityInformation);
}
simulationIslandConnection.Owner = this;
//Add the new reference back.
if (deactivationManager != null)
deactivationManager.Add(simulationIslandConnection);
}
While I expect I can configure Bepu to not even create simulation islands for these projectiles (although I forget offhand how to do it) I do have other objects created in a similar manner that need to roll around a bit before being removed so that optimization won't always make sense.
Thanks for any feedback,