Faster saves
(Warning: technical, but short, gamedev post)
In the next alpha version of Adaptory, I’ve rewritten the save game format to support much faster loads and saves:
Test | old (.ymlz) | new (.jsonz) |
---|---|---|
Saving | 1405ms | 284ms |
Loading | 9139ms | 349ms |
File size | 383kb | 396kb |
In the old format, save games were YAML files (.yml
), combined and zipped into
a single archive (.ymlz
). This worked great, because I want the save files
to be readable and eventually moddable by players.
However, I was finding that loading save files was taking quite a while. Loading an existing save would often take 10 seconds or more, for a pretty simple world. Upon investigation I found that the entire file had to be loaded into memory as a string, and then parsed as a single object, before the world could be created.
Ideally, I’d swap the YAML serialization library to one that supported streaming, because then you are reading, processing, and initialising all in a single stream, minimising the amount of memory you need to use. However I couldn’t find any Java YAML parsers that supported streaming.
I therefore made the decision to rewrite serialization using JSON. (I also considered XML.)
This means that Adaptory save games are now JSON files (.json
), combined and zipped into a single archive (.jsonz
).
Using GSON as our JSON serialization library has worked great – everything is much faster, so much so that I don’t even think I need to write a progress bar for loading anymore 😅
This does however mean that old save files are no longer compatible –
I’ll be keeping the old .ymlz
save game loader temporarily in Alpha 11,
but I’ll be removing it in Alpha 12,
so make sure to download a copy of the next demo version and migrate any old saves you might have.