duck.place

I lied - 23 Mar 2022

Two days ago I said the following in my devlog:

“if you save a level now it should be forward compatible with new versions for some time”

Well, I just broke that format. Sort of. I’ve added compression to the level files. So while the underlying format that the game uses to serialize a level is the same, before it is saved it gets compressed which changes the actual bytes. When the game loads a level it now expects a compressed level which means that old saves are now broken.

I didn’t expect compression to be necessary. When saving using the file icon the level is encoded as an image. Considering how many pictures of megabyte proportions are saved casually, a few kb is probably not a concern for anyone.

The pressure to keep level size down comes from the link sharing. Since levels are assumed to be authored by humans I had a rough idea of how big most levels would be. I estimated that levels more than about 50kb when encoded as b64 url strings would be rare. The server which stores shortened links for 24 hours is technically capable of megabyte long expanded urls. Furthermore, modern browsers can also handle quite big urls. The common rule of thumb seems to be to keep urls under 2000 characters but this is to ensure compatibility with any possible client. However, most browsers are not so picky. Firefox states a 65kb character limit for query urls. Safari says 80kb. Chrome is fine with 2mb.

Though I failed to consider one part of the equation. When the short links get expanded this happens through a redirect. My current solution expects destination urls to be max 16kb. 16kb levels are much more common. So I decided that compression was needed ASAP.

The current compression solution uses Godot’s built in compression with zstd as the backend. The compression ratio varies of course but seems to be high enough to be useful. I tried creating a level that exceeded the 16kb limit and had to spam a lot of items to the point that performance became a much bigger issue (I will eventually optimize performance as well) than level size.

It is of course still possible to go over the 16kb limit, no compression can stop that. Though I doubt most levels will. There is a work-around if this happens. Saving through the file icon has no limit as the level is encoded as an image.

As for the future: It would be nice not to be limited by 16kb for shared links. At some point I may consider a dedicated server for storing levels. A fast and reliable server, capable of storing levels indefinitely, can be costly. Now is not really the time. But who knows what the future holds.