12 comments

  • eliasdejong13 hours ago
    Author here,<p>First of all, hello Hacker News :)<p>Many of the comments seem to address the design of key hashing. The reason for using hashed keys inside B-tree nodes instead of the string keys directly is threefold:<p>1) The implementation is simplified.<p>2) When performing a lookup, it is faster to compare fixed-sized elements than it is to do variable length string comparison.<p>3) The key length is unlimited.<p>I should say the documentation page is out of date regarding hash collisions. The format now supports probing thanks to a PR merged yesterday. So inserting colliding keys will actually work.<p>It is true that databases and other formats do store string keys directly in the nodes. However as a memory format, runtime performance is very important. There is no disk or IO latency to &#x27;hide behind&#x27;.<p>Right now the hash function used is DJB2. It has the interesting property of somewhat preserving the lexicographical ordering of the key names. So hashes for keys like &quot;item_0001&quot;, &quot;item_0002&quot; and &quot;item_0003&quot; are actually more likely to also be placed sequentially inside the B-tree nodes. This can be useful when doing a sequential scan on the semantic key names, otherwise you are doing a lot more random access. Also DJB2 is so simple that it can be calculated entirely by the C preprocessor at compile time, so you are not actually paying the runtime cost of hashing.<p>We will be doing a lot more testing before DJB2 is finalized in the spec, but might later end up with a &#x27;better&#x27; hash function such as XXH32.<p>Finally, TRON&#x2F;Lite³ compared to other binary JSON formats (BSON, MsgPack, CBOR, Amazon Ion) is different in that:<p>1) none of the formats mentioned provide direct zero-copy indexed access to the data<p>2) none of the formats mentioned allow for partial mutation of the data without rewriting most of the document<p>This last point 2) is especially significant. For example, JSONB in Postgres is immutable. When replacing or inserting one specific value inside an object or array, with JSONB you will rewrite the entire document as a result of this, even if it is several megabytes large. If you are performing frequent updates inside JSONB documents, this will cause severe write amplification. This is the case for all current Postgres versions.<p>TRON&#x2F;Lite³ is designed to blur the line between memory and serialization format.
    • p0w3n3d39 minutes ago
      That&#x27;s really impressive. As you wrote it in C it gets automatically compilable to webasm and usable in js. I wonder how Java would behave here... As JNI is not the fastest (used to be not the fastest?)
    • andreyvit10 hours ago
      Hey, I&#x27;m sorry, but your Postgres example is completely wrong: because of MVCC, a new version of the data will be stored on every update regardless of the choice of data representation, making the in-place mutability much less of an advantage. (It might be faster than a pair of a compact immutable format + mutable patch layer on top, or it might be slower; the answer ain&#x27;t immediately obvious to me!)<p>What you should be imagining instead is a document database entirely built around Lite³-encoded documents, using something like rollback journals instead of MVCC.<p>We&#x27;re doing something similar in my company, storing zero-serialization immutable [1] docs in a key-value store (which are read via mmap with zero copying disk-to-usage) and using a mutable [2] overlay patch format for updates. In our analytics use cases, compact storage is very important, in-place mutability is irrelevant (again because of Copy-on-Write at the key-value store level), and the key advantage is zero serialization overhead.<p>What I&#x27;m saying is that Lite³ is a very timely and forward-looking format, but the merging of immutable and mutable formats into one carries tradeoffs that you probably want to discuss, and the discussion into the appropriate use cases is very much worth having.<p>[1] <a href="https:&#x2F;&#x2F;github.com&#x2F;andreyvit&#x2F;edb&#x2F;blob&#x2F;main&#x2F;kvo&#x2F;immutable.go" rel="nofollow">https:&#x2F;&#x2F;github.com&#x2F;andreyvit&#x2F;edb&#x2F;blob&#x2F;main&#x2F;kvo&#x2F;immutable.go</a> [2] <a href="https:&#x2F;&#x2F;github.com&#x2F;andreyvit&#x2F;edb&#x2F;blob&#x2F;main&#x2F;kvo&#x2F;mutable.go" rel="nofollow">https:&#x2F;&#x2F;github.com&#x2F;andreyvit&#x2F;edb&#x2F;blob&#x2F;main&#x2F;kvo&#x2F;mutable.go</a>
      • eliasdejong9 hours ago
        Hi, you are right in calling out the Postgres example in the context of DBs&#x2F;MVCC. The purpose of JSONB is to be an indexable representation of JSON inside a Postgres database. It is not trying to be a standalone format for external interchange and therefore it is fulfilling very different requirements.<p>A serialization format does not care about versioning or rollbacks. It is simply trying to organize data such that it can be sent over a network. If updates can be made in-place without requiring re-serialization, then that is always a benefit.<p>Write amplification is still a fact however that I think deserves to be mentioned. To tackle this problem in the context of DBs&#x2F;MVCC, you would have to use techniques other than in-place mutation like you mention: overlay&#x2F;COW. Basically, LMDB-style.<p>And yes I think databases is where this technology will eventually have the greatest potential, so that is where I am also looking.
  • cryptonector6 days ago
    Lite^3 is a clever encoding for JSON data that is indexed as-encoded and is mutable in place.<p>Perhaps I should have posted this URI instead: <a href="https:&#x2F;&#x2F;lite3.io&#x2F;design_and_limitations.html" rel="nofollow">https:&#x2F;&#x2F;lite3.io&#x2F;design_and_limitations.html</a><p>Lite^3 deserves to be noticed by HN. u&#x2F;eliasdejong (the author) posted it 23 days ago but it didn&#x27;t get very far. I&#x27;m hoping this time it gets noticed.
    • Someone16 hours ago
      FTA#1: <i>“Hashmaps do not (efficiently) support range queries. Since the keys are stored in pseudorandom order”</i><p>FTA#2: <i>“Object keys (think JSON) are hashed to a 4-byte digest and stored inside B-tree nodes”</i><p>It still will likely be faster because of better cache locality, but doesn’t that means this also does not (efficiently) support range queries?<p>That page also says<p><i>“tree traversal inside the critical path can be satisfied entirely using fixed 4-byte word comparisons, never actually requiring string comparisons except for detection of hash collisions. This design choice alone contributes to much of the runtime performance of Lite³.”</i><p>How can that be true, given that this beats libraries that use hash maps, that also rarely require string comparisons, by a large margin?<p>Finally, <a href="https:&#x2F;&#x2F;lite3.io&#x2F;design_and_limitations.html#autotoc_md37" rel="nofollow">https:&#x2F;&#x2F;lite3.io&#x2F;design_and_limitations.html#autotoc_md37</a> says:<p><i>“Inserting a colliding key will not corrupt your data or have side effects. It will simply fail to insert.”</i><p>I also notice this uses the DJB2 hash function, which has hash collisions between short strings (<a href="http:&#x2F;&#x2F;dmytry.blogspot.com&#x2F;2009&#x2F;11&#x2F;horrible-hashes.html" rel="nofollow">http:&#x2F;&#x2F;dmytry.blogspot.com&#x2F;2009&#x2F;11&#x2F;horrible-hashes.html</a>), and those are more likely to be present in json documents. You get about 8 + 3 × 5 = 23 bits of hash for four-character strings, for example, increasing the risk of collisions to, ballpark, about one in three thousand.<p>=&gt; I think that needs fixing before this can be widely used.
      • nneonneo15 hours ago
        Looking at the actual code (<a href="https:&#x2F;&#x2F;github.com&#x2F;fastserial&#x2F;lite3&#x2F;blob&#x2F;main&#x2F;src&#x2F;lite3.c#L242" rel="nofollow">https:&#x2F;&#x2F;github.com&#x2F;fastserial&#x2F;lite3&#x2F;blob&#x2F;main&#x2F;src&#x2F;lite3.c#L2...</a>), it seems like it performs up to 128 probes to find a target before failing, rather than bailing immediately if a collision is detected. It seems like maybe the documentation needs to be updated?<p>It&#x27;s a bit unfortunate that the wire format is tied to a specific hash function. It also means that the spec will ossify around a specific hash function, which may not end up being the optimal choice. Neither JSON nor Protobuf have this limitation. One way around this would be to ditch the hashing and use the keys for the b-tree directly. It might be worth benchmarking - I don&#x27;t think it&#x27;s necessarily any slower, and an inline cache of key prefixes (basically a cheapo hash using the first N chars) should help preserve performance for common cases.
        • Someone13 hours ago
          &gt; It seems like maybe the documentation needs to be updated<p>Looks like it, yes:<p><pre><code> &#x2F;** Enable hash probing to tolerate 32-bit hash collisions. Hash probing configuration (quadratic open addressing for 32-bit hashes: h_i = h_0 + i^2) Limit attempts with `LITE3_HASH_PROBE_MAX` (defaults to 128). Probing cannot be disabled. *&#x2F; #ifndef LITE3_HASH_PROBE_MAX #define LITE3_HASH_PROBE_MAX 128U #endif #if LITE3_HASH_PROBE_MAX &lt; 2 #error &quot;LITE3_HASH_PROBE_MAX must be &gt;= 2&quot; #endif </code></pre> &gt; It also means that the spec will ossify around a specific hash function<p>It is a bit ugly, and will break backwards compatibility, but supporting a second hash function isn’t too hard.<p>You can, on load, hash a few keys, compare them to the hashes, and, from that, if the input has many keys with high probability, infer which hash function was used.<p>There also might be spare bit somewhere to indicate ‘use the alternative hash function’.<p>Reading the code (nice-looking, BTW, for C code, but since it is C code, also full of warnings that other languages can protect you from) I spotted this (<a href="https:&#x2F;&#x2F;github.com&#x2F;fastserial&#x2F;lite3&#x2F;blob&#x2F;acbb97984eca1183ddcc76cd7413dc388062b171&#x2F;include&#x2F;lite3.h#L698" rel="nofollow">https:&#x2F;&#x2F;github.com&#x2F;fastserial&#x2F;lite3&#x2F;blob&#x2F;acbb97984eca1183ddc...</a>):<p>&gt; The JSON standard requires that the root-level type always be an ‘object&#x27; &gt; or &#x27;array&#x27;. This also applies to Lite³.<p>I don’t think that is true, and <a href="https:&#x2F;&#x2F;www.json.org&#x2F;json-en.html" rel="nofollow">https:&#x2F;&#x2F;www.json.org&#x2F;json-en.html</a> agrees with that. Single values (numbers, strings, booleans, null) also are valid json.
    • eric-p718 hours ago
      This needs more attention than it&#x27;s getting. Perhaps if you made some changes to the landing pages could help?<p>&quot;outperforms the fastest JSON libraries (that make use of SIMD) by up to 120x depending on the benchmark. It also outperforms schema-only formats, such as Google Flatbuffers (242x). Lite³ is possibly the fastest schemaless data format in the world.&quot;<p>^ This should be a bar graph at the top of the page that shows both serializing sizes and speeds.<p>It would also be nice to see a json representation on the left and a color coded string of bytes on the right that shows how the data is packed.<p>Then the explanation follows.
      • sirfz14 hours ago
        As already mentioned in other comments, it doesn&#x27;t really make sense to compare to json parsers since lite3 parses, well, lite3 and not json. It serves a different use case and I think focusing on performance vs json (especially json parsers) is not the best thing about this project
    • dang2 hours ago
      I&#x27;ve added that second link to the toptext.<p>I&#x27;m sorry we missed that Show HN (<a href="https:&#x2F;&#x2F;news.ycombinator.com&#x2F;item?id=45992832">https:&#x2F;&#x2F;news.ycombinator.com&#x2F;item?id=45992832</a>)! It belonged in the SCP (<a href="https:&#x2F;&#x2F;news.ycombinator.com&#x2F;item?id=26998308">https:&#x2F;&#x2F;news.ycombinator.com&#x2F;item?id=26998308</a>).
  • bawolff15 hours ago
    This is cool, but the headline makes it sound like the wire format is json compatible which is not the case. I&#x27;m not really sure why there is a focus on json here at all - its the least interesting part of this and the same could be said for almost every serialization format.
  • tarasglek15 hours ago
    hash collision limitation for keys is the most questionable part of design. Usually thats handled by forcing key lookup to verify that what you looked up matches what you tried to lookup. Resolving this perf hit is probably doable by having an extra table of conflicting hashes
    • eliasdejong13 hours ago
      (author here)<p>The documentation page is out of date, the format now resolves collisions through quadratic probing.
  • lsb16 hours ago
    This is super interesting!<p>Apache Arrow is trying to do something similar, using Flatbuffer to serialize with zero-copy and zero-parse semantics, and an index structure built on top of that.<p>Would love to see comparisons with Arrow
  • mhalle11 hours ago
    It would be interesting to use lite3 for blob storage in or with sqlite.
    • weitendorf9 hours ago
      That&#x27;s kind of similar to my project collector: <a href="https:&#x2F;&#x2F;github.com&#x2F;accretional&#x2F;collector" rel="nofollow">https:&#x2F;&#x2F;github.com&#x2F;accretional&#x2F;collector</a><p>It&#x27;s protobuf&#x2F;grpc based but uses json for serialization to make use of sqlite&#x27;s json filtering functionality. However, it cannot be said to be zero-copy. It serializes binary protos into json and stores the binary protos directly for fast access, which allows you to skip deserialization when pulling out query results
  • al2o3cr6 days ago
    The docs mention that space for overwritten variable-sized values in the buffer is not reclaimed:<p><pre><code> The overridden space is never recovered, causing buffer size to grow indefinitely. </code></pre> Is the garbage at least zeroed? Otherwise seems like it could &quot;leak&quot; overwritten values when sending whole buffers via memcpy
    • mjd17 hours ago
      “By default, deleted values are overwritten with NULL bytes (0x00). This is a safety feature since not doing so would leave &#x27;deleted&#x27; entries intact inside the datastructure until they are overwritten by other values. If the user wishes to maximize performance at the cost of leaking deleted data, LITE3_ZERO_MEM_DELETED should be disabled.”
  • koolala17 hours ago
    GLTF is like this too (or PLY)? The main difference is the format of their headers? Just by reading the header you can parse the binary data. I&#x27;m surprised BSON and any of the other binary JSON formats they list don&#x27;t support reading the memory layout in a header.
  • Jean-Papoulos14 hours ago
    This is nice, but please don&#x27;t clickbait headlines with straight-up lies. This is <i>not</i> JSON-compatible.
    • koolala13 hours ago
      Yeah JSON compatable is very different from convertable.
  • rixed17 hours ago
    So it&#x27;s not really a serialization format, it&#x27;s a compact, modifiable untyped tree, that one can therefore send to another machine with the same architecture. Or deserialise into native language specific data structures.<p>Don&#x27;t get me wrong, I find this type of data structures interesting and useful, but it&#x27;s misleading to call it &quot;serialization&quot;, unless my understanding is wrong.
    • bawolff14 hours ago
      I&#x27;m not sure what the distinction you are trying to make here is?<p>How does machine architecture play into it? It sounds like int sizes are the same regardless of word sizes of the machine, the choices made just happen to have high performance for common machine architectures. Or is it about endianess? Do big endian machines even exist anymore?
      • rixed47 minutes ago
        Yes, integer sizes, float sizes, endianess, alignment requirement...
    • jesse__2 hours ago
      What is a serialization format, if not a data encoding &quot;that one can therefore send to another machine&quot; .. &quot;Or deserialise into native language specific data structurs&quot; ..?<p>I&#x27;m very confused by your comment.
    • koolala16 hours ago
      You have to encode the type of all the binary data. Does that make it serialization?
  • yIt9R810 hours ago
    The benchmarks are flawed, verification is not generally used after serialization with flatbuffers. Deserialization with flatbuffers is a simple reinterpret_cast so it makes no sense for it to be 41.69ms.<p>It&#x27;s just dishonest.
  • IshKebab4 hours ago
    I&#x27;m suspicious of their FlatBuffers performance comparison.