I just installed node-msgpack and tested it against native JSON. MessagePack is much slower. Anyone know why?
Using the authors' own benchmark...
node ~/node_modules/msgpack/bench.js
msgpack pack: 4165 ms
msgpack unpack: 1589 ms
json pack: 1352 ms
json unpack: 761 ms
I'll assume you're talking about https://github.com/pgriess/node-msgpack.
Just looking at the source, I'm not sure how it could be. For example in
src/msgpack.cc
they have the following:In node terms, they are allocating and filling a new
SlowBuffer
for every request. You can benchmark the allocation part by doing following:So by just allocating memory for the message they've already spent 60% of
stringify
time. There's just one reason why it's so much slower.Also take into account that
JSON.stringify
has gotten a lot of love from Google. It's highly optimized and would be difficult to beat.