Live data from Hacker News

Binary Formats Are Better Than JSON in Browsers

adamfaulkner.github.io

11–18 of 18 posts

Re: Binary Formats Are Better Than JSON in Browsers

#11

We are using binary formats in production, also for data visualization and analysis. We went for a simple custom format: in addition to the usual JSON types (string, number, array, boolean, object), the serialized value can contain the standard JSON types, but can also contain JavaScript typed arrays (Uint8Array, Float32Array, etc). The serialized data contains the raw data of all the typed arrays, followed by a sing…

Usually for such scenarios, in the context of distributed systems, I tend to rely on general purpose monitoring tools, or a quick and dirty mini gateway if I can't reach for them.

Re: Binary Formats Are Better Than JSON in Browsers

#12
> During this process, I benchmarked a number of different binary encodings. To my surprise, I found that all of them were much slower than JSON in browsers.

I doubt this a lot. Even turning a small JSON message into a pre-defined character-delimited string is at least an order of magnitude faster than JSON. In my testing, at least. in my testing over the years, JSON has always been the slowest thing to extract information out of, no matter how you approach it. And any binary format will be faster than just about any text format.

developers think binary stuff is scary, or somehow harder than text, but it isn't. binary is faster, smaller, and depending on your use case, more flexible.

I use type-length-value for just about everything binary. it's easy to understand later with a hex editor if you need to, but obviously documentation helps understanding this greatly. and no documentation for these format is the code which reads it.

binary formats. good. try it. tell your friends.

Re: Binary Formats Are Better Than JSON in Browsers

#13

I've been working with the VS Code codebase for the past few months and I noticed they're encoding/decoding all the IPC messages using a custom binary buffer implementation (or at least I think that's the case, some of the code is hard to follow). It struck me as odd because most of the messages are pretty small (definitely not 100s of MB). I always wondered: at what point does it become more performant to encode mes…

I don't know, but I'm struck by the observation that binary formats are "just" a special case of compression.

Re: Binary Formats Are Better Than JSON in Browsers

#14

I've been working with the VS Code codebase for the past few months and I noticed they're encoding/decoding all the IPC messages using a custom binary buffer implementation (or at least I think that's the case, some of the code is hard to follow). It struck me as odd because most of the messages are pretty small (definitely not 100s of MB). I always wondered: at what point does it become more performant to encode mes…

I don't know, but I'm struck by the observation that binary formats are "just" a special case of compression.

Well, they're not, they're just an efficient way of encoding a subset of data. They can't compress that data, like, for example, compressing 100 x "a", unless they have a compression algorithm attached, they will just represent "a" 100 times, but more efficiently than unicode or whatever.

Re: Binary Formats Are Better Than JSON in Browsers

#16

Earlier quoted context omitted.

I don't know, but I'm struck by the observation that binary formats are "just" a special case of compression.

Well, they're not, they're just an efficient way of encoding a subset of data. They can't compress that data, like, for example, compressing 100 x "a", unless they have a compression algorithm attached, they will just represent "a" 100 times, but more efficiently than unicode or whatever.

It's almost as you'd have compressed that string 100 into a single byte.

Re: Binary Formats Are Better Than JSON in Browsers

#17
post #10

They are better everywhere, it makes no sense replicating CORBA and DCOM, parsing text all the time. It is always a matter of tooling, being able to easily look into whatever they might contain. I guess at least JSON-RPC (which most REST is actually about) isn't as bad as SOAP.

I remember working in a large corporate on a central integration broker (from memory it was Java based).

The CPU required for marshalling and demarshalling JSON and SOAP was easily over 80% of the workload. And yes, you are right SOAP is worse.

I always thought is probably an opportunity to create hardware accelerators for this type of workloads.

Re: Binary Formats Are Better Than JSON in Browsers

#18

MessagePack seems to use string field names. I wonder how it would perform with integer field keys defined (which MessagePack also supports).

Here's a benchmark of int keys in .NET https://github.com/MessagePack-CSharp/MessagePack-CSharp#des...
Post reply on HN