TE
TechEcho
Home24h TopNewestBestAskShowJobs
GitHubTwitter
Home

TechEcho

A tech news platform built with Next.js, providing global tech news and discussions.

GitHubTwitter

Home

HomeNewestBestAskShowJobs

Resources

HackerNews APIOriginal HackerNewsNext.js

© 2025 TechEcho. All rights reserved.

MessagePack: It's like JSON, but fast and small.

102 pointsby davikr4 months ago

18 comments

buserror4 months ago
I played quite a bit with MessagePack, used it for various things, and I don&#x27;t like it. My primary gripes are:<p>+ The Object and Array needs to be entirely and deep parsed. You cannot skip them.<p>+ Object and Array cannot be streamed when writing. They require a &#x27;count&#x27; at the beginning, and since the &#x27;count&#x27; size can vary in number of bytes, you can&#x27;t even &quot;walk back&quot; and update it. It would have been MUCH, MUCH better to have a &quot;begin&quot; and &quot;end&quot; tag --- err pretty much like JSON has, really.<p>You can alleviate the problems by using extensions, store a byte count to skip etc etc but really, if you start there, might as well use another format altogether.<p>Also, from my tests, it is not particularly more compact, unless again you spend some time and add a hash table for keys and embed that -- but then again, at that point where it becomes valuable, might as well gzip the JSON!<p>So in the end it is a lot better in my experience to use some sort of &#x27;extended&#x27; JSON format, with the idiocies removed (trailing commas, forcing double-quote for keys etc).
评论 #42695636 未加载
评论 #42665532 未加载
评论 #42664719 未加载
ubutler4 months ago
Although MessagePack is definitely <i>not</i> a drop-in replacement for JSON, it is certainly extremely useful.<p>Unlike JSON, you can’t just open a MessagePack file in Notepad or vim and have it make sense. It’s often not human readable. So using MessagePack to store config files probably isn’t a good idea if you or your users will ever need to read them for debugging purposes.<p>But as a format for something like IPC or high-performance, low-latency communication in general, MessagePack brings serious improvements over JSON.<p>I recently had to build an inference server that needed to be able to communicate with an API server with minimal latency.<p>I started with gRPC and protobuf since it’s what everyone recommends, yet after a lot of benchmarking, I found a way faster method to be serving MessagePack over HTTP with a Litestar Python server (it’s much faster than FastAPI), using msgspec for super fast MessagePack encoding and ormsgpack for super fast decoding.<p>Not sure how this beat protobuf and gRPC but it did. Perhaps the Python implementation is just slow. It was still faster than JSON over HTTP, however.
评论 #42668384 未加载
评论 #42664622 未加载
mdhb4 months ago
CBOR: It’s like JSON but fast and small but also an official IETF standard.<p><a href="https:&#x2F;&#x2F;cbor.io&#x2F;" rel="nofollow">https:&#x2F;&#x2F;cbor.io&#x2F;</a>
评论 #42664664 未加载
评论 #42664201 未加载
评论 #42664558 未加载
toomim4 months ago
MessagePack saves a little bit of space and CPU ... but not a lot:<p><a href="https:&#x2F;&#x2F;media.licdn.com&#x2F;dms&#x2F;image&#x2F;v2&#x2F;D5612AQF-nFt1cYZhKg&#x2F;article-inline_image-shrink_1000_1488&#x2F;article-inline_image-shrink_1000_1488&#x2F;0&#x2F;1703965440210?e=2147483647&amp;v=beta&amp;t=XOmhYJP5X6iYJ17RYsk3SjX9FTvfcZbQFP-OTOg6flk" rel="nofollow">https:&#x2F;&#x2F;media.licdn.com&#x2F;dms&#x2F;image&#x2F;v2&#x2F;D5612AQF-nFt1cYZhKg&#x2F;art...</a><p>Source: <a href="https:&#x2F;&#x2F;www.linkedin.com&#x2F;pulse&#x2F;json-vs-messagepack-battle-data-efficiency-akshay-singh-kanawat-7dx2c" rel="nofollow">https:&#x2F;&#x2F;www.linkedin.com&#x2F;pulse&#x2F;json-vs-messagepack-battle-da...</a>
评论 #42664300 未加载
评论 #42670575 未加载
评论 #42665415 未加载
janalsncm4 months ago
In my experience protobuf was smaller than MessagePack. I even tried compressing both with zstd and protobuf was still smaller. On the other hand protobuf is a lot less flexible.
评论 #42664545 未加载
karteum4 months ago
I discovered JSON Binpack recently, which works either schemaless (like msgpack) or - supposedly more efficiently - with a schema. I haven&#x27;t tried the codebase yet but it looks interesting.<p><a href="https:&#x2F;&#x2F;jsonbinpack.sourcemeta.com&#x2F;" rel="nofollow">https:&#x2F;&#x2F;jsonbinpack.sourcemeta.com&#x2F;</a>
fshafique4 months ago
Does it solve the problem of repeating set of keys in an object array, eg. when representing a table?<p>I don&#x27;t think using a dictionary of key values is the way to go here. I think there should be a dedicated &quot;table&quot; type, where the column keys are only defined once, and not repeated for every single row.
评论 #42664465 未加载
评论 #42664574 未加载
sd94 months ago
It drops the most useful aspect of JSON, which is that you can open it in a text editor.<p>It&#x27;s like JSON in that it&#x27;s a serialisation format.
评论 #42665488 未加载
vdqtp34 months ago
Ignorant question - is the relatively small size benefit worth another standard that&#x27;s fairly opaque to troubleshooting and loses readability?<p>Is there a direct comparison of why someone should choose this over alternatives? 27 bytes down to 18 bytes (for their example) just doesn&#x27;t seem like enough of a benefit. This clearly isn&#x27;t targeted to me in either case, but for someone without much knowledge of the space, it seems like a solution in search of a problem.
评论 #42663949 未加载
评论 #42664653 未加载
评论 #42663966 未加载
评论 #42664445 未加载
评论 #42663944 未加载
评论 #42664303 未加载
评论 #42664451 未加载
评论 #42663941 未加载
accelbred4 months ago
I really like MessagePack as a serialization format but it does leave a lot underspecified, such as how to handle decoding&#x2F;encoding integers. While the encoding has signed and unsigned types, the data model does not. Its not straightforward to translate to a data midel with separate signed and unsigned types.<p>The separation between str and bin types doesnt make sense for my usecases, and others with similar usecases either always use bin or always use str. logically bin would make sense, but str has fixstr and theres no fixbin, so more efficient to use str. Both are valid but thats more discrepancies to deal with.<p>For my personal usecases I&#x27;m thinking of forking MessagePack, removing str and ext, reallocting tag space a bit, having a clear mapping to low level language types, adding 128 bit integers, and maybe a frame type for streams.
slurpyb4 months ago
Shouts to msgspec - i havent had a project without it in awhile.
评论 #42664473 未加载
dallbee4 months ago
A trick I often use to get the most out of messagepack is using array encoding of structs. Most msgp libraries have support for this.<p>This gives you a key benefit of protobuf, without needing external schema files: you don&#x27;t have to pay the space of the keys of your data.<p>This is simply not something you can do with JSON, and depending on your data can yield substantial space savings.
xcircle4 months ago
In our C++ project, we use the nlohmann library for handling JSON data. When sending JSON over MQTT, we leverage a built-in function of nlohmann to serialize our JSON objects into the MessagePack format. You can simply call jsonObj.to_msgpack(). Similarly, the data can be decoded back easily.
mattbillenstein4 months ago
I&#x27;ve built a few systems using msgpack-rpc - serves really well as a transport format in my experience!
jedisct14 months ago
ZigPack is a pretty good MessagePack implementation written in Zig: <a href="https:&#x2F;&#x2F;github.com&#x2F;thislight&#x2F;zigpak">https:&#x2F;&#x2F;github.com&#x2F;thislight&#x2F;zigpak</a>
eeasss4 months ago
Serialziation vulnerabilities anyone
h_tbob4 months ago
I like how it makes binary easy. I wish there was a simple way to do binary in JSON.
agieocean4 months ago
Made an open image format with this for constrained networks and it works great