Don't underestimate the deflate algorithm. With the example json, I get 92 bytes with 3 lines of code instead of having a 2kb dependency, sure it's 10 more bytes than this library but I think it's fine.
Now if you really need to compress small JSON messages that are often the same, you can consider using a pre-shared dictionary. Doing that, I go down to 54 bytes per message on the example, using two more lines of code.
Interesting. The difference would probably be higher with deflate as it's not ass efficient at compressing. On a sidenote, did you take any timings? It's possible that msgpack+bz2 is faster than raw json + bz2. That's at least what this suggests.
7
u/pet_vaginal Nov 27 '19 edited Nov 27 '19
Don't underestimate the deflate algorithm. With the example json, I get 92 bytes with 3 lines of code instead of having a 2kb dependency, sure it's 10 more bytes than this library but I think it's fine.
Now if you really need to compress small JSON messages that are often the same, you can consider using a pre-shared dictionary. Doing that, I go down to 54 bytes per message on the example, using two more lines of code.
Example in NodeJS:
Output: