Live data from Hacker News

Data serialization

enqueuezero.com

21–30 of 91 posts

Re: Data serialization

#21
One topic not brought up in this is versioning/change management. While I have my criticisms of Json, if I decide to add a new field to my object, most JSON parsers have the advantage that they'll just consider my old data without that field to have a full value there. XML, same thing.

How does protobuf or MsgPack handle that? Aren't they both trying to align data by byte number at some deep level? Or do I not understand them?

Re: Data serialization

#22
post #5

Regarding JSON, this page says: > Performance is not good when dataset is huge. Program usually needs to load all data into memory first. This is just downright false. There are plenty of SAX-style JSON parsers.

I think it's point is that JSON isn't a great streaming format; which it isn't.

That's not to say there aren't streaming decoders available or workarounds to allow non-streaming decoders to emulate streaming behaviour. However generally JSON parsers require the full JSON object before they can decode.

Re: Data serialization

#23
post #20
post #16

Earlier quoted context omitted.

Just to add another dimension to your analysis, if you're sending large binaries the 33% overhead of Base64 adds up pretty quickly. It may not apply to your use case but if you are delivering images or video over a websocket it can make a big difference.

On the other hand, gzip can reclaim most of those 33% with Huffman encoding.

That's something I hadn't considered. I'll have to do some benchmarking. Thanks!

Re: Data serialization

#24

Don't we do CSV/TSV anymore? It's certainly the most basic schema-less data format imaginable, and you can even have field names using the convention that the first row contains field names. It might be considered out of fashion today in our staged this-vs-that culture, but I don't see anything wrong with it. Tab-separated-values are just data fields separated by a distinguished character, with rows separated by anot…

CSV standards are flawed and it has a lot of weird edge cases.

Moreover, byte encoding formats are more concise, so faster to transport over the wire and store and the schema seldom proves to be an hindrance, as it assists in data validation and acts as documentation.

Re: Data serialization

#25
post #19
post #3

Dealing with data as my day job I've become highly sensitive to schema's. And I hate those "schemaless" (aka schema-on-read) serialization formats more and more. No, there is no schemaless, there is a schema, but it is buried in your code in a convoluted way on each line where you read and interpret your deserialised data and all tests and assumptions you have there are a horrible representation of your schema. That…

I really wish we had a JSON 2 format which could fix JSON's obvious shortcomings. I would like to see: - Support for Maps and Sets (unlike objects, maps allow arbitrary types to be used as keys) - A standard Date format - Embedded binary blobs. No idea how to do this and keep it human readable, but when you need this its super useful. Maybe something similar to WS's binary message encoding. - Arbitrary precision inte…

Arbitrary precision integers is a JavaScript implementation detail; JSON standard doesn't specify number precision.

Re: Data serialization

#26
post #6

I read somewhere the problem with MsgPack is, that JSON has a rather fast parser build into JavaScript that beats the MsgPack parser. So you would have to check if the saved bandwidth would be enough to justify the slower parsing. Would be interesting if this still holds true with a WASM implementation.

That's the case with Perl at least. Both JOSN::XS and Cpanel::JSON::XS are faster than Data::MessagePack and Sereal on an iMac 2009 with Yosemite. On Linux Sereal is 53% faster than Data::MessagePack, but the rest of the benchmark is quite similar. CBOR::XS beats just about any data serializer. Sereal is quite sophisticated, it can compress data using snappy, zlib and zstd.

            Rate msgpack  sereal cjsonxs  jsonxs  cborxs
    msgpack 204848/s      --     -2%     -6%    -18%    -34%
    sereal  208207/s      2%      --     -4%    -16%    -33%
    cjsonxs 217825/s      6%      5%      --    -13%    -29%
    jsonxs  249011/s     22%     20%     14%      --    -19%
    cborxs  308571/s     51%     48%     42%     24%      --
All the module versions tested are current. Here is the code for this benchmark:

https://hastebin.com/wazuqovexo.pl

Re: Data serialization

#27
post #3

Dealing with data as my day job I've become highly sensitive to schema's. And I hate those "schemaless" (aka schema-on-read) serialization formats more and more. No, there is no schemaless, there is a schema, but it is buried in your code in a convoluted way on each line where you read and interpret your deserialised data and all tests and assumptions you have there are a horrible representation of your schema. That…

1000x yes!

Schemas are defined somewhere, even if it's a poor and bug-ridden definition in the code. Ditto for the point that JSON doesn't count.

I wrote an article, On Schemas, to try and elaborate on this topic a bit.

https://adamdrake.com/on-schemas.html

Re: Data serialization

#28
post #21

One topic not brought up in this is versioning/change management. While I have my criticisms of Json, if I decide to add a new field to my object, most JSON parsers have the advantage that they'll just consider my old data without that field to have a full value there. XML, same thing. How does protobuf or MsgPack handle that? Aren't they both trying to align data by byte number at some deep level? Or do I not unders…

Protobuf has supported this for as long as I’ve used it. You add an optional field for the new data. And there’s a couple other considerations. (Docs: [0])

Fields have a number, which you can/should mark as reserved after you take it out. Then future developers won’t use a field that was something else in the past. [1]

Since version all fields are optional ( they removed the required field feature). So your app has to check that the fields you want (in that version of your app) are present.

[0] https://developers.google.com/protocol-buffers/docs/proto3#u...

Re: Data serialization

#29
> Performance is not good when dataset is huge. Program usually needs to load all data into memory first.

You could use a streaming parser, or, more easily, NDJSON (assuming your data is huge, because it's a list of stuff). Just save each JSON as a line in a file and then stream the file line by line, only parsing one line at a time. That's fairly fast and allocates very little memory.

Re: Data serialization

#30

Don't we do CSV/TSV anymore? It's certainly the most basic schema-less data format imaginable, and you can even have field names using the convention that the first row contains field names. It might be considered out of fashion today in our staged this-vs-that culture, but I don't see anything wrong with it. Tab-separated-values are just data fields separated by a distinguished character, with rows separated by anot…

"It might be considered out of fashion today in our staged this-vs-that culture, but I don't see anything wrong with it.... no API required."

Well, it has no type system, not even "string vs. number", no hierarchy of any kind (no objects, no lists, nothing going deeper), and CSV/TSV is actually a meta-specification requiring a correct use of CSV to provide a complete specification (since you can trust literally nothing about a CSV/TSV implementation otherwise) so you can handle the distinguished characters in the data values. Whatever it is you are about to say is the answer to that problem is not; it is an answer and there are others in common use, and correct usage needs to specify them.

Unlike the formats listed, it's completely unclear how to serialize arbitrary objects into it in a way that other people would agree to sight-unseen. That is, yes, I'm aware you can jam anything you want into CSV. For instance, you could make one of the columns be JSON. But that defeats the purpose of claiming it's good enough on its own, no? Same for any other scheme you might propose; unless you can show it to be a standard, it's not an answer, just an ad-hoc solution.

I'm not saying it's useless. Literally used it last Friday to dump some data into something that could be loaded by a spreadsheet program so someone can mix & match the data without having to ask for every individual possible view to come straight from me. Very useful format at times. But as a generalized serialization format? It's not even in the running, which is precisely why it doesn't come up in these discussions.

If you want to get concrete, show me the canonical way you'd lossly serialize the DOM tree nodes for the HN home page into CSV, in a way that you are reasonably sure is the same way everybody else would tend to if given the task, then show me the emitter and generator code that is more convenient than the alternatives.

Post reply on HN