3 ms·
For me the advantage of msgpack is simplicity / efficiency in parsing the response. If you are decoding a JSON string, you run over the string twice: first to
by drewcrawford 14y ago
For me the advantage of msgpack is simplicity / efficiency in parsing the response.
If you are decoding a JSON string, you run over the string twice: first to search for the terminating quote character so that you know how much memory to allocate, and second to copy the string.
Whereas with msgpack, it's more like pascal-model strings where you know the length of the string up front; you can do it one pass. You also get some structural hints that make more of the parsing a parallelizable problem, whereas with JSON it is very difficult to get any benefit out of more cores.
This may not make any difference if you are serving up an API request or three to x86 computers with broadband, but they make a lot of difference if the data you're working with is large relative to the bandwidth or latency of the pipe or the CPU power available on the other side of it.
- stock_toaster 14y ago> For me the advantage of msgpack is simplicity / efficiency in parsing the response If you like that, you might want to take a look at tnetstrings as a format.
- drewcrawford 14y agoSimple, yes. Efficient, no. For example, msgpack can encode a 2-byte binary blob in 3 bytes. tnetstrings takes eleven bytes, for no appreciable benefit in decoding time. Also there's this gem: > You are not allowed to implement any of the following features: UTF-8 Strings glances at title of article