2 ms·
We use this technique in Just Dance Now, and I wholeheartedly recommend doing it for usecases where you need to compress lots of small packets individually. We
by polyfemos76 12y ago
We use this technique in Just Dance Now, and I wholeheartedly recommend doing it for usecases where you need to compress lots of small packets individually. We save at least 50% data.
For our game, this consists of the normal communication going back and forth between server and client, where individual messages are normally <100b.
By sampling some user sessions we built a dictionary, fed it into deflateSetDictionary/inflateSetDictionary, and use that in both Node modules for the server, as well as throughout the ecosystem of Android and iOS.
It's very simple to do; we base all communication on standard JSON (for ease of portability and debugging) but then have the preset-dictionary fed into zip (a simple large string!) to counter the weight of JSON.
Needless to say, binary packing the protocol would give additional gains; but the productivity gains with using dictionaries to get good compression of pure JSON was a great choice for us. And it's really supersimple to do.
One nice benefit is that the protocol is extendable by any developer without worrying about the wire-transport; the compression won't break is someone decides to add a parameter to a message, it just most likely won't be compressed as well as the rest of the message.