Izumi.SICK 0.1.9

dotnet add package Izumi.SICK --version 0.1.9                
NuGet\Install-Package Izumi.SICK -Version 0.1.9                
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="Izumi.SICK" Version="0.1.9" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add Izumi.SICK --version 0.1.9                
#r "nuget: Izumi.SICK, 0.1.9"                
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
// Install Izumi.SICK as a Cake Addin
#addin nuget:?package=Izumi.SICK&version=0.1.9

// Install Izumi.SICK as a Cake Tool
#tool nuget:?package=Izumi.SICK&version=0.1.9                

Build Latest Release Maven Central Latest version

SICK: Streams of Independent Constant Keys

SICK is an approach to handle JSON-like structures and various libraries implementing it.

SICK allows you to achieve the following:

  1. Store JSON-like data in efficient indexed binary form
  2. Avoid reading and parsing whole JSON files and access only the data you need just in time
  3. Store multiple JSON-like structures in one deduplicating storage
  4. Implement perfect streaming parsers for JSON-like data
  5. Efficiently stream updates for JSON-like data

The tradeoff for these benefits is somehow more complicated and less efficient encoder.

The problem

JSON has a Type-2 grammar and requires a pushdown automaton to parse it. So, it's not possible to implement efficient streaming parser for JSON. Just imagine a huge hierarchy of nested JSON objects: you won't be able to finish parsing the top-level object until you process the whole file.

JSON is frequently used to store and transfer large amounts of data and these transfers tend to grow over time. Just imagine a typical JSON config file for a large enterprise product.

The non-streaming nature of almost all the JSON parsers requires a lot of work to be done every time you need to deserialize a huge chunk of JSON data: you need to read it from disk, parse it in memory into an AST representation, and, usually, map raw JSON tree to object instances. Even if you use token streams and know the type of your object ahead of time you still have to deal with the Type-2 grammar.

This may be very inefficient and causes unnecessary delays, pauses, CPU activity and memory consumption spikes.

The idea

Let's assume that we have a small JSON:

[
    {"some key": "some value"},
    {"some key": "some value"},
    {"some value": "some key"},
]

Let's build a table for every unique value in our JSON :

Type index Value Is Root
string 0 "some key" No
string 1 "some value" No
object 0 [string:0, string:1] No
object 1 [string:1, string:0] No
array 0 [object:0, object:0, object:1] Yes (file.json)

We just built a flattened and deduplicated version of our initial JSON structure.

Streaming

Such representation allows us to do many different things, for example we may stream our table:

string:0 = "some key"
string:1 = "some value"

object:0.size = 2
object:0[string:0] = string:1
object:1[string:1] = string:0

array:0.size = 2
array:0[0] = object:0
array:0[1] = object:1

string:2 = "file.json"

root:0=array:0,string:2

This particular encoding is inefficient but it's streamable and, moreover, we can add removal message into it thus supporting arbitrary updates:

array:0[0] = object:1
array:0[1] = remove

There is an interesting observation: when a stream does not contain removal entries it can be safely reordered. Unfortunately, in some usecases the receiver still may need to accumulate the entries in a buffer until it can sort them out.

Binary format: EBA (Efficient Binary Aggregate)

We may note that the only complex data structures in our "Value" column are lists and (type, index) pairs. Let's call such pairs "references".

A reference can be represented as a pair of integers, so it would have a fixed byte length.

A list of references can be represented as an integer storing list length followed by all the references in their binary form. Let's note that such binary structure is indexed, once we know the index of an element we want to access we can do it immediately.

A list of any fixed-size scalar values can be represented the same way.

A list of variable-size values (e.g. a list of strings) can be represented the following way:

  {strings count}{list of string offsets}{all the strings concatenated}

So, ["a", "bb", "ccc"] would become something like 3 0 2 3 a b bb ccc without spaces.

An important fact is that this encoding is indexed too and it can be reused to store any lists of variable-length data.

EBA Structures

TODO: explain the overall EBA structure format, including tables, etc

Additional capabilities over JSON

SICK encoding follows compositional principles of JSON (a set primitive types plus lists and dictionaries), though it is more powerful: it has "reference" type and allows you to encode custom types.

(1) It's easy to note that our table may store circular references, something JSON can't do natively:

Type index Value Is Root
object 0 [string:0, object:1] No
object 1 [string:1, object:0] No

This may be convenient in some complex cases.

(2) Also we may note, that we may happily store multiple json files in one table and have full deduplication over their content. We just need to introduce a separate attribute (is root) storing either nothing or the name of our "root entry" (JSON file).

In real implementation it's more convenient to just create a separate "root" type, the value of a root type should always be a reference to its name and a reference to the actual JSON value we encoded:

Type index Value
string 0 "some key"
string 1 "some value"
string 2 "some value"
object 0 [string:0, string,1]
object 1 [string:1, string:0]
array 0 [object:0, object:0, object:1]
root 0 [string:2, array:0]

(3) We may encode custom scalar data types (e.g. timestamps) natively just by introducing new type tags.

(4) We may even store polymorphic types by introducing new type tags or even new type references.

Implementation

Currently we provide C# and Scala implementations of SICK indexed binary JSON storage. Currently the code in this repository has no streaming capabilities. That may change in the future. It's not a hard problem to add streaming support, your contributions are welcome.

Language Binary Storage Encoder Binary Storage Decoder Stream Encoder Stream Decoder Encoder AST Decoder AST
Scala Yes No No No Circe N/A
C# Yes Yes No No JSON.Net Custom
Supported types

A type marker is represented as a single-byte unsigned integer. The possible values are:

Marker Name Comment Value Length (bytes) C# mapping Scala Mapping
0 TNul Equivalent to null in JSON 4, stored in the marker
1 TBit Boolean 4, stored in the marker
2 TByte Byte, 4, stored in the marker byte (unsigned) Byte (signed)
3 TShort Signed 16-bit integer 4, stored in the marker
4 TInt Signed 32-bit integer 4
5 TLng Signed 64-bit integer 8
6 TBigInt Variable, prefixed
7 TDbl 8
8 TFlt 4
9 TBigDec Variable, prefixed Custom: scale/precision/signum/unscaled quadruple in C#
10 TStr UTF-8 String Variable, prefixed
11 TArr List of array entries Variable, prefixed
12 TObj List of object entries Variable, prefixed
15 TRoot Index of the name string (4 bytes) + reference (4+1=5 bytes) 9
References

TODO

Lists

TODO

Array entries

Array entries are just references.

Object entries

TODO

Object entry skip list and KHash

TODO

Value tables

TODO

Limitations

Current implementation has the following limitations:

  1. Maximum object size: 65534 keys
  2. The order of object keys is not preserved
  3. Maximum amount of array elements: 2^32
  4. Maximum amount of unique values of the same type: 2^32

These limitations may be lifted by using more bytes to store offset pointers and counts on binary level. Though it's hard to imagine a real application which would need that.

Product Compatible and additional computed target framework versions.
.NET net5.0 was computed.  net5.0-windows was computed.  net6.0 was computed.  net6.0-android was computed.  net6.0-ios was computed.  net6.0-maccatalyst was computed.  net6.0-macos was computed.  net6.0-tvos was computed.  net6.0-windows was computed.  net7.0 was computed.  net7.0-android was computed.  net7.0-ios was computed.  net7.0-maccatalyst was computed.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed.  net8.0 was computed.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed. 
.NET Core netcoreapp3.0 was computed.  netcoreapp3.1 was computed. 
.NET Standard netstandard2.1 is compatible. 
MonoAndroid monoandroid was computed. 
MonoMac monomac was computed. 
MonoTouch monotouch was computed. 
Tizen tizen60 was computed. 
Xamarin.iOS xamarinios was computed. 
Xamarin.Mac xamarinmac was computed. 
Xamarin.TVOS xamarintvos was computed. 
Xamarin.WatchOS xamarinwatchos was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
0.1.9 69 10/24/2024
0.1.9-alpha.101.1.11543131792 43 10/27/2024
0.1.9-alpha.100.1.11543099574 34 10/27/2024
0.1.9-alpha.99.1.11543029531 39 10/27/2024
0.1.9-alpha.97.1.11542766659 35 10/27/2024
0.1.9-alpha.96.1.11542759889 35 10/27/2024
0.1.9-alpha.95.1.11542743035 36 10/27/2024
0.1.9-alpha.92.1.11535380531 35 10/26/2024
0.1.9-alpha.91.1.11534754760 32 10/26/2024
0.1.9-alpha.90.1.11534728272 35 10/26/2024
0.1.9-alpha.84.1.11524147279 33 10/25/2024
0.1.9-alpha.80.1.11501877492 31 10/24/2024
0.1.8 110 9/11/2024
0.1.8-alpha.78.1.11501836223 35 10/24/2024
0.1.8-alpha.77.1.10816114029 53 9/11/2024
0.1.6 248 11/13/2023
0.1.6-alpha.74.1.10815646116 50 9/11/2024
0.1.6-alpha.73.1.10779432710 49 9/9/2024
0.1.6-alpha.72.1.10779398369 47 9/9/2024
0.1.6-alpha.71.1.10779340615 46 9/9/2024
0.1.6-alpha.70.1.10779255916 53 9/9/2024
0.1.6-alpha.69.1.10778956854 48 9/9/2024
0.1.6-alpha.68.1.10778347980 48 9/9/2024
0.1.6-alpha.67.1.10773767841 44 9/9/2024
0.1.6-alpha.66.1.10773391549 48 9/9/2024
0.1.6-alpha.65.1.10309929078 70 8/8/2024
0.1.6-alpha.64.1.9569809415 52 6/18/2024
0.1.6-alpha.63.1.9569252981 50 6/18/2024
0.1.6-alpha.62.1.9569209999 53 6/18/2024
0.1.6-alpha.61.1.7489993321 65 1/11/2024
0.1.5 148 11/2/2023
0.1.5-alpha.60.1.7489990759 62 1/11/2024
0.1.5-alpha.58.1.6855319998 95 11/13/2023
0.1.5-alpha.56.1.6852209177 62 11/13/2023
0.1.5-alpha.55.1.6777279602 66 11/6/2023
0.1.5-alpha.54.1.6777234035 70 11/6/2023
0.1.5-alpha.53.1.6777218278 66 11/6/2023
0.1.5-alpha.52.1.6734224890 65 11/2/2023
0.1.3 153 9/13/2023
0.1.3-alpha.50.1.6174784251 80 9/13/2023
0.1.2 147 9/13/2023
0.1.1 146 9/13/2023
0.1.0-alpha.46.1.6174266386 84 9/13/2023
0.1.0-alpha.45.1.3857949337 99 1/6/2023
0.1.0-alpha.44.2.3849219603 99 1/6/2023
0.1.0-alpha.44.1.3849219603 100 1/5/2023
0.1.0-alpha.42.1.3849045352 95 1/5/2023
0.1.0-alpha.41.3.3848986268 97 1/5/2023
0.1.0-alpha.41.1.3848986268 98 1/5/2023
0.1.0-alpha.39 100 1/5/2023
0.1.0-alpha.38 103 1/5/2023
0.1.0-alpha.37 96 1/5/2023
0.1.0-alpha.36 99 1/5/2023
0.1.0-alpha.35 101 1/4/2023
0.1.0-alpha.34 95 1/4/2023
0.1.0-alpha.33 100 1/4/2023
0.1.0-alpha.32 97 1/4/2023
0.1.0-alpha.31 96 1/4/2023
0.1.0-alpha.30 97 1/4/2023
0.1.0-alpha.29 97 1/4/2023
0.1.0-alpha.28 97 1/4/2023
0.1.0-alpha.27 91 1/4/2023
0.1.0-alpha.26 97 12/29/2022
0.1.0-alpha.25 96 12/29/2022
0.1.0-alpha.24 95 12/29/2022
0.1.0-alpha.23 93 12/29/2022
0.1.0-alpha.22 88 12/23/2022
0.0.2-alpha.21 92 12/23/2022
0.0.2-alpha.20 98 12/21/2022
0.0.2-alpha.16 92 12/21/2022
0.0.2-alpha.15 94 12/21/2022
0.0.2-alpha.14 92 12/21/2022
0.0.2-alpha.4 90 12/21/2022
0.0.2-alpha.3 93 12/21/2022
0.0.2-alpha.2 95 12/21/2022
0.0.2-alpha.1 92 12/21/2022
0.0.2-alpha 129 12/21/2022