Caching for multiplayer map download
Posted: Tue Nov 02, 2021 12:06 am
TL;DR
Allow multiplayer maps to be cached so only the changed parts need downloading, decreasing download time.First off, this is nothing I realistically see being implemented, although a guy can dream
Why ?
Maps that get explored a lot can get pretty big, especially when using mods like SpaceExploration.This is a problem when playing on a server, since every reconnect requires a full map download. When not using a dedicated server, that is usually limited by the hosts upload speed. For big maps, this takes quite some time. Afterwards we need to "catch up" when the server wasn't paused, exacerbating the problem. When your save is bigger than 100MB, or even 250MB, this is very painful.
One crash due to a mod misbehaving, and you need to do it all over again. Caching to reduce the download time would help alleviate those problems.
Those threads come up from time to time, for example here: viewtopic.php?t=92114
Necessary for vanilla? Probably not. With mods it would be very useful, though.
How ?
I came up with an idea how it could be handled, that I'd like to put up for discussion.My idea is caching the map on the client: After a successful connect to the server, the client saves the map as "checkpoint save".
When the next time the save is played, we can make the following assumption:
- All factory elements, pollution, enemies, and so on will most likely change.
- The explored but not touched terrain is probably still the same - we'll call that "probably not changing data"
This would include tiles, trees, resources, decorations and maybe more.
A connection would look like this:
- Client can always request a full map transfer, or a partial map transfer
- For a full map transfer, we use the existing logic. Otherwise:
- Server calculates a checksum(md5) for each chunk, only including the "probably not changing data".
- Send list of chunk coordinates with their checksums to the client
- Client compares the checksums to the chunks it has from the "checkpoint". Client drops all chunks the server doesn't have.
- Client sends the server a list of chunk coordinates that it does not have
- Server sends map data, excluding the "probably not changing data" for the chunks the client already has
- Client downloads partial map and merges it with the "checkpoint"
All transmissions would again be zlib compressed, to minimize data needed to transmit.
Of course I don't know exactly how factorio serializes the saves, or how easy that would be to implement. But theoretically this should allow us to cut transmitted map size by quite a margin for maps that have a lot of untouched explored terrain.
Thoughts and comments?