The International Simutrans Forum

Development => Technical Documentation => Topic started by: prissi on October 13, 2016, 09:09:31 PM

Title: Impact of zlib compression levels
Post by: prissi on October 13, 2016, 09:09:31 PM
I a blog on compiling the server I found a remark about explicitely setting the compression level to the lowest level of zlib via gzopen(filename, "wb1"). I tested this with my usual test game.


level size time for load/save
1 3664kb 4045/1393ms
6 2985kb 4052/1386ms
9 2882kb 4042/5110ms
default 2975kb 4144/1507ms


One can argue to set it to level six; but the default already does a good job too. Exspecially that at good downlaod rates of 16 MBit (or realistic about one MB per second) the differences between level 1 and default are 200 ms longer compression but 600 ms shorter download.

Anyway, nice to know there is a parameter to play around. (And I am happy to see your impact.)
Title: Re: Impact of zlib compression levels
Post by: DrSuperGood on October 13, 2016, 11:40:50 PM
Maybe some sort of algorithm could be used to select an appropriate compression level? Specifically if a person with a slow connection is trying to join then it uses a higher compression level. Would need extensive statistical testing to get the algorithm to be vaguely accurate.
Title: Re: Impact of zlib compression levels
Post by: TurfIt on October 14, 2016, 01:08:32 AM
4096x4096 map

levelsize (kB)    load (ms)    save (ms)
1  291072880  1360
6  195492880  3440
9  18244287016575
default  195562870  3450
bzip def        9748427533380
binary2216572850  1270

Hard to beat the zip default IMO.
Title: Re: Impact of zlib compression levels
Post by: prissi on October 14, 2016, 08:38:25 AM
When you have a server with a slow upload then you can already use bzip. That gives better compression than any zip mode.

NB: The same method of forcing a level can be done for bzip. But again default does a good job too, albeit a much slower one than zip.
Title: Re: Impact of zlib compression levels
Post by: DrSuperGood on October 14, 2016, 03:42:16 PM
Might be a good idea to add a special "maximum compression" save option that uses the maximum compression level. Although not at all practical for servers or single player saving, it would be intended for save game publication. For example hand-made maps or scenarios could be saved with such a configuration for smaller file size so they are quicker to download.