Show HN: Avsc – a pure JavaScript Avro implementation
github.com
github.com
I've never heard of Avro, but it looks really interesting. Could you enlighten me on some use cases, and situations where it really shines?
I like to think of Avro in two (related) parts:
+ A very compact binary serialization, which lets you efficiently store or transfer data over the wire. (Avro actually also defines a way to encode your data as JSON in cases when you need a human-readable representation.)
+ A way to define "data types". For example this schema [1] defines what we expect a "Human" entry to look like, and we can now do things like check whether we are missing any information, make sure all fields are valid, sort, efficiently copy objects, etc.
This is glossing over many things (files, RPC, ...) but I hope this helps a bit! You can find a lot more information in the official Avro documentation [2] if you're curious.
[1] https://github.com/mtth/avsc/blob/master/etc/benchmarks/sche...
The benchmarks show a fair number of -1s (not supported). What isn't supported exactly? I don't see these limitations listed in the limitations section.
Performance-wise, the main benefits came from doing as much preprocessing as possible. Here are a couple examples of what is done when a schema is parsed:
+ All methods for encoding and decoding nested types get fully resolved, removing the need for lookups (for example an array of integers would have a reference to the method for encoding integers).
+ A constructor, and encoding/decoding methods gets programmatically generated for each record type. This avoids having to iterate over the fields each time. Same for unions. (Having a "Class" for each record type also lets us attach useful methods to its prototype, available for all record instances.)
Then there are a few other general ideas like making sure v8 is able to optimize all the methods on the critical path, or reusing buffers as much as possible to avoid allocating too many objects.
We define all of our records in protocols in avdls, I'm assuming this doesn't handle avdls as of yet?