Original Post
I am writing a rendering system in C# and have come to a point where the CPU is severely bottle-necking the performance of a test. Honestly, I'll admit that this is just some optimize-before-it's-time-curiosity but I still would like to know what's going on for future reference. Each frame I'm adding collections of simple 6-vertex quads (for sprites) to a List of vertices. When it's time to render I simply lock the VertexBuffer and pop them in then draw. With 12,000 verts per frame I was doing fine at ~10 ms but with 60,000 it started hitting 50-60ms. Within the function that adds new verts to the List I allocate a simple Array and then copy the current image's verts into it, transform them and then add that to the List like so: I managed to boil the entire performance hit down to that last line. If I took it out, everything else fell right back down to ~10ms. On a hunch I decided to use a List uniformly across the board like so: After that, everything was happily hanging around 25ms. Trouble is I can't seem to actually get the transformation within that ForEach block to work. I can't access the data any other way without some kind of complex conversion and tossing of data everywhere. And then it just brings me right back up to the 45-50ms range. For now I can safely go back to the conversion between Lists and Arrays but I'm worried about problems in the future where I can't get away with that. Any advice? For reference I did my timing both with QPC and PIX and tested all scenarios with locking and drawing both on and off. I'm certain that it isn't a GPU stall anywhere.
DeviceVertex[] TempVerts = (DeviceVertex[])graphic.Verts.ToArray();
for(int i = 0; i < GlobalRendererSettings.VertsPerSprite; i++)
{
TempVerts.x += xPos*2;
TempVerts.y += yPos*2;
}
//... later...
list.Verts.AddRange(TempVerts);
List<DeviceVertex> verts = new List<DeviceVertex>(6);
TempVerts = graphic.Verts;
TempVerts.ForEach(delegate(DeviceVertex v)
{
v.x += (xPos*2);
v.y += (yPos*2);
} );