Well, I did a bit of programming this morning before work, and on the way driving to work I had one of those "Wait a second..." moments. Here's the guilty section of code:
private void GenerateMapFromGraph(MapNode current, Map map, Point seam, ParenthoodChain parentChain)
{
if (current.Generated)
return;
current.Generated = true;
bool placed = false;
System.Console.WriteLine(string.Format("Generating {0} - {1}", current.Type.ToString(), current.UniqueID.ToString()));It's that last line that got me. It was some debugging code that I forgot to remove. This function gets called recursively during map generation, a huge number of times and writing to stdout is very slow.
Some baseline numbers (release mode attached to debugger) in generating 100 maps gives me:
- Before - 47473ms
- After - 1041ms
The lesson for today, next time performance is terrible, check stdout to make sure you aren't dumping 10000 lines of text to it during map generation.
Update: Now I just need to find some crazy optimization for my cave map generator and I can get rid of my "loading" screen, since I can generate 100 of the stitch levels in about a second.
