What is the best compression library for very small amounts of data?
06:17 17 Feb 2010

My game engine descended from Quake 2, adding scripted effects to specify effects to a client instead of a limited number of hardcoded effects.

The maximum packet size is 2800 bytes and only one can go out per client per frame. The sparks effect script I have done everything to shrink (even reduced variable names to single letters) to 405 bytes, at most 6 of these fit per frame. Only 41 would be unique between multiple usages of the effect. This is a candidate for compression.

R1Q2 (a backward-compatible Quake 2 engine with an extended network protocol) has zlib compression code. But is zlib the best choice? I can think of LZMA and more.

  1. Must be very fast (very small performance hit if run over 100 times a second).
  2. Highest compression rate possible into 2800 bytes.
  3. Small metadata footprint.
  4. GPL compatible.

I am compiling the scripts into bytecode. This gets a 1172 byte source down to 405 bytes (not small enough). There is no guarantee that any given packet will arrive. Each contains the state of the world without relying on previous packets. These scripts if there's no room get dropped from the packet. If too many get dropped things look strange.

network-programming lossless-compression quake