Slow loading on Windows

With the new loading screen timing stuff in place, I’ve discovered something a little surprising.

On my computer, if I’m running in Linux, it takes about 2 seconds to parse a saved game. On the same computer running Windows, it takes almost 28 seconds. The time it takes to build the map data is basically the same, regardless of which OS is running. This is a huge surprise to me; I had always assumed that the slow part of the load was going to be building the map data… but something is really slowing down the loading of the save file itself, only on Windows, and by a lot!

Interestingly, if I run that same Windows build using Wine under Linux, it runs just as fast as the native Linux binary! The slow load only seems to happen using the Windows build if you’re actually running Windows. Which implies that the slowdown is probably happening inside a system call which is slow on Windows, and fast on Linux. There are probably lots of those. Mutexes is one common example. But parsing the save file is single-threaded; no mutexes are involved at all. So… this is going to be interesting!

I’m going to do some debugging over the next few days to try to figure this all out. There’s no good reason for the the build to be so much slower when running on Windows!

Three hours of debugging later, the culprit has been found!

It turns out that file access seems to be quite slow on Windows. Or at least, it’s quite slow when done through physfs. I haven’t actually tested direct file access, but I’m inclined to think that it’s Windows, rather than physfs.

In the current VectorStorm, I’m reading files byte-by-byte as I require their data, in order to keep from needing to read them entirely into memory at any point. But it turns out that this is staggeringly slow on Windows.

I did a quick hack-job of rewriting VectorStorm’s vsFile class to load a whole file into memory all at once, and then simply perform fake “read some more bytes of the file” operations out of that memory buffer instead of actually going to the disk. Doing this has dropped my save-game-loading times on Windows from 28 seconds down to about 2.5 seconds in total. (It speeds up the Linux build as well, but not anything remotely as dramatic).

I’ll be cleaning this up, and will try to get another Steam build out soon, with vastly faster loads on Windows. :smiley: