Slow Load Time!

I’ve always had issues with games that have long load times. Especially ones where you end up loading more often than not because of mistakes, failure, and death. This goes triple if you’re writing a game. I start and stop the game 50 times a day while coding and debugging.

My game hasn’t been having fast load times.

When I started writing the game I wrote a bunch of code  knowing it would help with this issue:

  • The data is in ready to use state. Any processing of a resource is done as a pre-process that the player will never see. 
  • A single file is used to contain all resources so that opening and closing several thousand files isn’t a bottleneck.
  • The data is compressed to around 40% of its original size to further reduce disk I/O time. Decompression occurs at load time and is very fast.

Because I had done all these things, I started to become disconcerted at the speed at which the game took to start. From prior experience,  I know a modern hard disc can read 100M in under a second, and the data for the game is just under that.

My philosophy for optimization is to write good code, and not worry about how fast it runs until I actually notice the game running slowly.  So when load times got to be around thirty seconds I noticed, and properly investigated with a code profiler.

It turned out the primary thread that is rendering the loading screen wasn’t giving up it’s execution time while waiting for the monitor v-sync to occur. The loading thread was executing less than 3% of total CPU time. This made all my good code run just once in a while.

Fixed that, and now the loading time is now under 2 seconds. Guess I did things right. Mostly. Phew.