We know that seek time is a major problem with optical media, so we’ll need to reduce it as much as possible to achieve our fast load times. There’s really only so much we can do to solve the problem
- Seek less by reading less files
- Seek less by organizing our files better
We’ve seen how to reduce the number of files read by using packfiles, which also helped by seek times a little bit. Since seek times are related to the physical distance and direction a drive head has to move, we’ll look at how to reduce seek times by arranging files on disc to minimize their distance.
We’ll also wrap up this series on load times with some tips and tricks to get that last bit of optimization.
The key to a good disc layout is to read in a linear order. Always reading in a single direction on the disc, ideally reading sequential files. Seeks forward aren’t as bad as seeks backwards. We also want to avoid layer switches, which cause the laser to refocus and can take quite a bit of time.
But how do we know what order to put files in? It’s really simple, we put them in the order we load files. It’s a simple matter of logging each file we open and then sort by this file log. Sorting by a file log does mean you’ll have to go through the and log the whole game, but you can have an automated nightly process do that.
The way disc layout is usually arranged is the start of the disc is the center and spirals outward, then the second layer starts at the outside and spirals in. Like this:
We know that the outside of the disc has higher throughput than the inside. So we can read faster if we arrange the data on the outside of the disc. So we actually want to push our data to the outside tracks:
Depending on the game, if you have extra space it might be worthwhile duplicating common data on the disc. This works best if you’re packing multiple files together. If you’re using packfiles as part of you filesystem, remember to sort the files inside the packfile by access order.
So that’s really the all there is to a good layout
- Arrange files sequentially by load order to minimize seeking
- Arrange data at the outside tracks to maximize throughput
Tips and Tricks
The three most important features for load times are asynchronous loading, compression and file layout, with packfiles to help keep things organized. However there’s still a number of techniques we can use to get even lower load times.
- Load once and share files. This one is pretty obvious – if two models share the same texture only load the texture once. I personally don’t believe this should be done inside the file manager since it’s more of an asset management issue, but I thought it should be mentioned.
- Remove dependent loads – where one file contains information to load other files. It reduces your ability to batch reads, preventing you from keeping the disc busy. It can be difficult to remove all dependent loads if you have a highly data dependent engine, hopefully you can load other files to hide the latency these loads introduce.
- Cache frequently read files by keeping a compressed copy in memory. This works best for small files that get referenced a lot.
- Preload files that you know will be used. If you know that a file will be used soon, and have memory to spare, it doesn’t hurt to start loading the file. This works well during boot and while the user waits at the main menu. Ideally you can integrate a preloading system into your level design, so you load levels in chunks hiding any load times.
- Optical drives read in large chunks (64kB – 256kB) into an internal read buffer. This means consecutive reads or multiple reads can be combined. If you have lots of small files to load you can combine multiple reads into a single large read. This will increase throughput and reduce seek time, but requires your file loader to understand file layout.
- Hard drive caching of files is possible on the 360 and PS3, with many PS3 games having actual installs PC-style. It’s a pretty good idea actually, and you should take advantage of the hard drive if your platform has one. You should read files from both the optical drive and hard drive at the same time to get the most benefit.