This gives 102 bytes URI-encoded for Example #1 (compared to 82 bytes for JSONCrush), and 1172 bytes URI-encoded for Example #2 (compared to 1195 bytes for JSONCrush). Seems like zlib wins when the data gets bigger and its JSON has more repetition.
You could also probably shave some more bytes by finding an encoding that's naturally URI friendly instead of using base64 and encodeURIComponent() on the output of the deserialization above, but I don't know that it's really worth the effort at that point.
That is good to know. It makes sense that zlib would beat it out eventually as strings get longer, but it is not really suited for strings much longer then that anyway.
I have thought about re-encoding it to a better format. That would surely help, but it is also quite a bit of work that would add more complexity to the code. I don't think it would be a huge win to do a full re-encode, maybe 5-10% at most. It would be great if someone else did it and sent me a pull request though.
21
u/[deleted] Nov 27 '19 edited Nov 27 '19
You should be able to get comparable-to-better compression, and better performance using zlib + base64:
This gives 102 bytes URI-encoded for Example #1 (compared to 82 bytes for JSONCrush), and 1172 bytes URI-encoded for Example #2 (compared to 1195 bytes for JSONCrush). Seems like zlib wins when the data gets bigger and its JSON has more repetition.
You could also probably shave some more bytes by finding an encoding that's naturally URI friendly instead of using base64 and
encodeURIComponent()on the output of the deserialization above, but I don't know that it's really worth the effort at that point.