A compact, hybrid row-columnar binary serialization format, faster and smaller than Protocol Buffers. No schema compilation, no dependencies. Go, Rust and JS.
The Go module, the Rust crate and the JavaScript (WebAssembly) package read and write the same bytes. An optional self-describing mode, colbin/JSON, makes a message convertible to JSON with nothing else on hand.
-
Hybrid row-columnar. A message is written in a row format, with one byte of header per field. Inside it, a collection of eight or more records is written column by column, each integer column through a transform and bit-packing. The choice is made per value when encoding, so a three-field document and a million-row table are the same format.
-
No precompilation step. The Go struct is the schema. There is no
.protofile, noprotocand no generated types;cbfield tags are optional. -
No dependencies. The Go module's
go.modhas norequireblock. -
Smaller and faster than Protocol Buffers, with one exception. In the measurements, against its two Go implementations: protobuf-go (reflection, as colbin) and vtprotobuf (code-gen). Both write the same bytes.
colbin against Protocol Buffers size encode: protobuf-go encode: vtprotobuf decode: protobuf-go decode: vtprotobuf bulk tables, over 16 384 rows 1.74× smaller 5.4× faster 2.1× faster 4.5× faster 2.7× faster tables of up to 16 384 rows 1.32× smaller 4.1× faster 1.38× faster 2.6× faster 2.0× faster single records 1.09× smaller 2.2× faster 1.2× slower 1.68× faster the same (1.03×) The exception: vtprotobuf encodes a single record 1.2× faster, because straight-line generated code beats a plan interpreted per field when there are no columns to write. colbin is the faster one in 5 of 25 documents. From eight records up the collection is written by columns, and colbin is ahead of both.
-
Self-describing mode (colbin/JSON). The schema section travels inside the message, so
ToJSONrenders it without the Go type. The section is a median of 68 to 627 bytes by dataset: under 0.1% of a table of thousands of rows, and more than the message itself on a document of tens of bytes.
data, err := colbin.Marshal(&order) // a struct, no tags required
err = colbin.Unmarshal(data, &back)
doc, err := colbin.MarshalSelfDescribing(&order) // colbin/JSON
text, err := colbin.ToJSON(nil, doc) // JSON, no schema or type neededThe target is bandwidth between services, storage and clients, without changing how the code that produces and consumes the data is written.
- JSON costs no setup. But every record carries its field names, and every number is decimal text. A list of a thousand records repeats every key a thousand times.
- Protocol buffers remove the names and encode numbers in binary. They need
a
.protofile, a compiler step and generated types kept in sync with the application's own. They also encode a list of records row by row: each row repeats every field tag, and each element pays a tag and a length. - Varints, used by protobuf for keys, lengths and integers, are compact but decoded byte by byte, in a loop whose trip count depends on the data.
colbin is designed around four constraints:
- The Go struct is the schema. Field ids come from optional
cbtags, or are derived from field names when there are none. - One format for every shape. A 30-byte message, a table of thousands of rows and a nested document of hundreds of kilobytes use the same encoding. The layout adapts per field, not per message.
- A message can be read without the producer's type. A schema section, sent out of band or embedded in the message, is enough to render it as JSON.
- Decoding never loops on data. Every size is either in a header or in a field whose width the header names.
Each decision below was kept because it measured better than the alternative.
RATIONALE.md records the measurements, including the ideas
that were reverted. INTERNALS.md specifies the format bit by
bit.
A message is a root descriptor byte followed by a key run — or, for a struct
at four key bits with no schema or dictionary, the key run alone: a sequence of
[key][descriptor][payload] fields, terminated by the end of the enclosing
length. The run's key width is chosen per run and recorded in the descriptor
that opens it:
| layout | fields | can skip an unknown field | |
|---|---|---|---|
| K4 (narrow) | [key:4][desc:4], one byte |
ids 1–16 | yes: the descriptor says how long the field is; the type comes from the schema |
| K8 (wide) | [key:8][desc:8], two bytes |
ids 1–255 | yes: the descriptor names a class with a known size rule |
A nested struct opens its own run, so a narrow struct can hold a wide one and the reverse. A type with more than 255 fields is split into pages of 255. Key 255 of each page links to the next, up to id 4 080. (INTERNALS §3–4, §6.5)
A field's id comes from one of two places.
From a tag. cb:"N" makes the field id N, and its wire key is N−1. A type
whose ids all fit in 1–16 uses the one-byte K4 field header.
From the field name. A field without a number takes fnv8 of its name
(FNV-1a folded to one byte). If that key is taken, it moves to the next free one
upward. Fields are assigned in declaration order, after all tagged fields. The
Rust and JavaScript implementations use the same hash, so an untagged Go struct
is readable from both.
type Reading struct { // no tags: ids from the names, K8 keys
SensorID uint64
Timestamp int64
Value float64
}
type Reading struct { // tags: explicit ids, K4 keys
SensorID uint64 `cb:"1"`
Timestamp int64 `cb:"2"`
Value float64 `cb:"3"`
}Untagged types stay compatible as long as fields keep their names and their relative order:
- New fields go at the end.
- A rename keeps the old id if the old name is put in the tag:
cb:"SensorID". - Reordering is only unsafe when two names hash to the same byte, because declaration order decides which one moves.
A field's name comes from its json tag. The name in the schema, in the
JSON view, and the one an unnumbered field hashes is the json tag's name when
there is one, then a name in the cb tag, then the Go name. The cb number
only places the field on the wire. So ID int64 `json:"id" cb:"1"` is id 1,
called id. json:"-" does not drop a field; cb:"-" does.
What an untagged type costs, measured on a six-field record: derived keys span 0–255, so the type always uses K8. That is one extra byte per present field: 33 B instead of 27, and 44 ns instead of 38 to encode. Decode time is the same. Both widths skip a field the reader does not know, so producer and consumer can add or drop fields independently either way.
Tags are therefore an optimization for size and for the narrow fast path, not a requirement. In a table, keys are written per column rather than per row, so the key width hardly matters there.
- Zero values are omitted. A field holding
0,"",false, or an empty slice or map is not written at all. - Integers are sign-and-magnitude, with the byte count in the descriptor:
- A value takes 1 to 8 bytes, as many as it needs.
- In K4 the descriptor is a byte count first: 0–3 carry no payload, 4–11
carry 1–8 bytes, 12–15 a length. The values 1–4 (1–3 and −1 for a signed
field) are the descriptor itself, so a
bool, a status code or a small count is one byte, key included. A negative value other than −1 takes the length form, one byte more. - K8 adds a varint form, which the encoder writes only when it is shorter: 3.34 B against 3.60 per field on ids 0–1000.
- Floats are written byte-reversed. The zero bytes of an IEEE-754 value are
the low mantissa bytes, and reversing them lets the byte count drop them:
1.0is 2 bytes, and afloat64holding an exactfloat32is 5. - Strings and blobs of up to 8 bytes carry no size in K4: the descriptor's byte count is the size. Longer ones carry a length of 1, 3 or 5 bytes. A decoded string is a sub-slice of the message, not a copy.
- No size is a varint. Every read of a size is a single load of a width the header already gave, so decoding never runs a loop whose trip count is data.
Nested structs, lists, tables and maps are written with a backpatched byte length:
- In K8, that length is what lets a reader skip a composite without knowing its type.
- In K4, a composite is the length form of the descriptor (
[key:4][1 1 0 f], the flag a struct's key width or a table), and the class comes from the schema. Composites therefore do not force the wide width.
Pointers distinguish "absent" from "zero":
- A nil pointer is omitted.
- A pointer to a zero value writes an explicit zero, 2 bytes. This is the only value the format writes just to mark presence.
- A pointer to a slice or a map is encoded as the slice or the map.
- A slice of pointers to structs,
[]*T, is encoded as the[]Tit points at: the same bytes, a table past 8 rows. A nil element is written as an empty struct.
Map keys are strings, integers or bools. Map values may be scalars, strings,
blobs, structs, any, or slices of structs or of scalars: map[K][]Struct writes each value as a list, or as a table past 8
rows. map[K]*Struct and map[K]*[]T are encoded as their pointees, a nil
value as an empty one. A type holding a map of slices uses K8.
A []Struct whose element fields are all columnable switches layout at
8 rows:
- Below 8 rows it is a list: each element is a key run.
- From 8 rows up it is a table: one key per column instead of one per field per row.
The choice is made per field, at encode time, and the two layouts have different descriptor classes, so the reader dispatches on what it finds.
A table of more than 4 096 rows is written in groups of 4 096, each its own set of columns. The encoder then transposes one group at a time rather than the whole table, which keeps its memory to a group's worth and its columns in cache: TPC-H's normalized tables encode 18–26% faster for 0.04% more bytes.
| six-field row | bytes per row |
|---|---|
| list of structs, 7 rows | 16.9 |
| table, 1 000 rows | 11.0 |
Each integer column goes through the column codec:
- First, a transform chosen per column: raw, delta, frame-of-reference or constant.
- Then the residuals are bit-packed in blocks of 128 values, at a width chosen
per block. 128 values at
wbits is exactly16wbytes, so every block is byte-aligned and no state crosses a block boundary.
| 256 × int64 | raw | encoded |
|---|---|---|
| monotonic ids | 2 048 B | 171 B |
| timestamps | 2 048 B | 235 B |
| constant zeros | 2 048 B | 3 B |
| random | 2 048 B | 2 051 B |
Decode runs at 1.3 ns per value and encode at 3.5. A struct containing a nested struct or a slice cannot be a column, and it stays a list at any length. (INTERNALS §6.2–6.3, §7)
colbin.SetPacked5(true) packs strings drawn from upper-case letters and
digits at about 5 bits per character:
- The encoder decides per string and falls back to plain bytes when packing would not be shorter, so turning it on never grows a message.
- The choice is recorded in each string's descriptor, so the reader needs no configuration.
- It costs a pass over every string on both sides, which is why it is off by default.
The wire carries no names and no types. The schema section is the type's encoding plan serialized: a key, a name and an op code per field. Nested and recursive types are hoisted into an indexed struct table, so a recursive type describes itself in finite space. It can travel two ways:
- Out of band, once per connection. Messages stay exactly the size
Marshalproduces. - Embedded (
MarshalSelfDescribing). This is colbin/JSON, the self-describing mode: root byte0xD4/0xDC, then the section, then the body. The body is byte for byte whatMarshalwrites.Unmarshalskips a section that is the Go type's own, and reads the message through any other one, matching fields by name (see below).ToJSON(nil, msg)renders the message with no schema and no Go type available.
A browser can therefore send a payload to a Go backend with no schema of its own:
codec.marshal(value).standalone goes into colbin.Unmarshal and lands in the
typed Go value. The browser numbers its fields 0, 1, 2 and types every integer as
int64, so the decoder matches each field to the Go one by name (json tag
first, then the Go name), skips fields the Go type does not have, leaves fields
the message does not have at zero, and converts numbers to the field's type —
refusing, with the field's name, a value that does not fit (int64 70000 into an
int16) and a float into an integer. Send .standalone, not .message: a
message with no section has nothing to match by and is read by the Go type's own
field ids. A foreign decode of 500 products costs about 1.3× the same records
written by Go and about a tenth of ToJSON followed by encoding/json.
The section is 38 to 448 bytes for the types measured here. On a table or a document that is under 1% of the message. On a single small record it is most of the message, which is why a stream of small messages should send the section once instead.
ToJSON's output has the same content as encoding/json's, with three
differences:
- Fields a record omitted are rendered after the ones it holds.
- Empty slices and maps render as
null. - NaN and infinity are refused.
any, []any and map[string]any are carried anywhere a typed field can go.
A dynamic value writes its own type on the wire: one descriptor byte naming
integer, float, string, blob, list, map, null, true or false.
An array of records inside a dynamic value is written behind a tag that refers to a struct in the section. The rows are then the same table a typed field would write. A thousand five-field records take:
- 26 024 B as a typed
[]User; - 26 067 B as
map[string]any{"rows": users}; - 78 196 B in
encoding/json.
go get github.com/ivanjoz/colbintype SaleLine struct {
ProductID uint32
Quantity uint32
UnitCents int64
}
type Sale struct {
ID uint64
CreatedAt int64
TotalCents int64
Lines []SaleLine // a table from 8 lines up
}
data, err := colbin.Marshal(&sale)
err = colbin.Unmarshal(data, &back)A handle resolves the type's plan once. After that, encode and decode allocate only what the decoded value itself needs:
var saleCodec = colbin.MustCodec[Sale]()
buf, err = saleCodec.Append(buf[:0], &sale)
err = saleCodec.Unmarshal(buf, &back)Generated code: codec.Generate emits the straight-line calls against the
wire package that one would write by hand.
| ten-field record | encode | decode |
|---|---|---|
hand-written against wire |
7.6 ns | 22.4 ns |
codec.Generate |
6.9 ns | 22.9 ns |
Codec[T] handle |
23.5 ns | 27.6 ns |
Marshal / Unmarshal |
52.7 ns | 48.5 ns |
Reading without the type:
schema, _ := colbin.SchemaFor[Sale]()
section := schema.Bytes() // send once
parsed, _ := colbin.ParseSchema(section) // on the reader
text, _ := colbin.ToJSON(parsed, message)
value, _ := colbin.DecodeAny(parsed, message) // map[string]any
standalone, _ := colbin.MarshalSelfDescribing(&sale) // colbin/JSON
text, _ = colbin.ToJSON(nil, standalone)The numbers are from the evaluation in colbin-benchmarks
(results/paper-v1): colbin v0.13.1 against 11 other formats and
implementations in Go, on 107 cases from four public datasets. They were
measured with Go 1.27.4 on an AMD EPYC 7J13 (Oracle Cloud, one core per
case), as the median of 10 samples.
How to read a cell. Each cell says how many times smaller or faster colbin is than the other format, as a geometric mean over the cases both formats carry. Above 1 colbin wins. Below 1 it loses, and the cell is in bold. A difference under about 4% is within what two runs of the same measurement differ by, so 1.03× is a tie.
- Size is the encoded message in bytes, as written, with no compression on either side.
- Time is encode into a reused buffer, then decode into a fresh value,
written as
encode / decode.
| format | implementation measured |
|---|---|
| JSON | encoding/json/v2 |
| gob | encoding/gob |
| CBOR | fxamacker/cbor |
| MessagePack | tinylib/msgp (generated code) and vmihailenco/msgpack (reflection) |
| Protocol Buffers | planetscale/vtprotobuf (generated code) and protobuf-go (reflection) |
| FlatBuffers | google/flatbuffers |
| Arrow | apache/arrow-go, IPC stream |
| Avro | hamba/avro |
| Cap'n Proto | capnproto.org/go/capnp |
Generated code needs a schema file and a compiler step. colbin, like the reflection libraries, needs neither, so both kinds are in the tables.
The cases are grouped by what a message is:
- Bulk tables: more than 16 384 rows (14 cases). An export or a backup.
- Web tables: a slice of up to 16 384 rows (66 cases). What a server sends a client in one response.
- Single records: one object with no table in it (25 cases).
Size: times smaller, as written.
| colbin against | bulk tables | web tables | single records |
|---|---|---|---|
| JSON | 5.9× | 3.9× | 3.3× |
| gob | 1.79× | 1.42× | 5.6× |
| CBOR | 4.7× | 3.2× | 2.6× |
| MessagePack | 4.7× | 3.2× | 2.6× |
| Protocol Buffers | 1.74× | 1.32× | 1.09× |
| FlatBuffers | 3.4× | 2.1× | 3.0× |
| Arrow | 2.7× | 2.1× | n/a |
| Avro | 1.46× | 1.19× | 0.91× |
| Cap'n Proto | 3.5× | 2.2× | 3.2× |
Time: times faster, encode / decode.
| colbin against | bulk tables | web tables | single records |
|---|---|---|---|
| JSON | 17.2× / 19.6× | 14.9× / 10.6× | 8.7× / 3.8× |
| gob | 6.5× / 5.0× | 11.6× / 6.6× | 35.6× / 49.9× |
| CBOR | 8.0× / 17.7× | 6.3× / 9.3× | 4.0× / 3.6× |
| MessagePack, generated | 1.47× / 3.0× | 1.23× / 2.1× | 0.66× / 0.82× |
| MessagePack, reflection | 12.0× / 16.1× | 10.4× / 8.5× | 7.9× / 3.9× |
| Protocol Buffers, vtprotobuf | 2.1× / 2.7× | 1.38× / 2.0× | 0.83× / 1.03× |
| Protocol Buffers, protobuf-go | 5.4× / 4.5× | 4.1× / 2.6× | 2.2× / 1.68× |
| FlatBuffers | 10.3× / 2.8× | 5.8× / 1.96× | 2.8× / 0.80× |
| Arrow | 3.4× / 1.62× | 6.7× / 2.2× | n/a |
| Avro | 3.0× / 5.3× | 2.6× / 3.7× | 2.5× / 1.19× |
| Cap'n Proto | 9.0× / 5.9× | 11.4× / 3.9× | 12.8× / 3.0× |
What the tables say:
- On tables colbin is smaller and faster than every format measured, on both operations. A table writes one key per column instead of one per field per row, and its integer columns go through the column codec.
- On single records there are no columns to write, and colbin is a row format like the others. Against Protocol Buffers it is 1.09× smaller (smaller in 19 of 25 documents) and decodes at vtprotobuf's speed.
- On single records colbin loses to generated code on time. To encode, vtprotobuf is 1.2× faster and generated msgpack 1.5× faster. To decode, generated msgpack is 1.2× faster and FlatBuffers 1.25× faster. Avro is 1.10× smaller. Straight-line generated code beats a plan interpreted per field on a message of a few fields.
- Arrow carries only tables, so it has no cell for single records. gob is timed only on the cases it round-trips (40 of the 80 tables): it does not transmit a pointer to a zero value.
Size: times smaller, as written.
| colbin against | TPC-H | TPC-DS | Public BI | SchemaStore |
|---|---|---|---|---|
| JSON | 2.3× | 5.2× | 4.2× | 3.3× |
| gob | 1.22× | 1.96× | 1.33× | 5.6× |
| CBOR | 1.94× | 4.2× | 3.5× | 2.6× |
| MessagePack | 1.94× | 4.2× | 3.5× | 2.6× |
| Protocol Buffers | 1.16× | 1.56× | 1.35× | 1.09× |
| FlatBuffers | 1.69× | 3.4× | 1.95× | 3.0× |
| Arrow | 1.52× | 4.7× | 1.65× | n/a |
| Avro | 1.06× | 1.32× | 1.23× | 0.91× |
| Cap'n Proto | 1.69× | 3.3× | 2.1× | 3.2× |
Time: times faster, encode / decode.
| colbin against | TPC-H | TPC-DS | Public BI | SchemaStore |
|---|---|---|---|---|
| JSON | 15.9× / 10.9× | 15.4× / 9.2× | 15.1× / 13.8× | 8.7× / 3.8× |
| gob | 8.5× / 5.6× | 13.0× / 7.8× | 8.5× / 5.0× | 35.6× / 49.9× |
| CBOR | 6.7× / 10.3× | 7.1× / 8.6× | 6.3× / 11.6× | 4.0× / 3.6× |
| MessagePack, generated | 1.29× / 2.1× | 1.21× / 1.68× | 1.30× / 2.7× | 0.66× / 0.82× |
| MessagePack, reflection | 11.0× / 9.2× | 12.6× / 8.2× | 9.7× / 10.4× | 7.9× / 3.9× |
| Protocol Buffers, vtprotobuf | 1.85× / 2.2× | 1.58× / 1.73× | 1.37× / 2.4× | 0.83× / 1.03× |
| Protocol Buffers, protobuf-go | 5.2× / 3.7× | 4.5× / 2.5× | 4.1× / 2.9× | 2.2× / 1.68× |
| FlatBuffers | 4.6× / 1.91× | 8.5× / 1.72× | 5.9× / 2.4× | 2.8× / 0.80× |
| Arrow | 7.1× / 1.93× | 12.5× / 2.8× | 3.9× / 1.78× | n/a |
| Avro | 3.0× / 2.4× | 2.9× / 3.2× | 2.5× / 4.9× | 2.5× / 1.19× |
| Cap'n Proto | 14.6× / 4.8× | 10.0× / 3.3× | 10.7× / 4.6× | 12.8× / 3.0× |
The datasets are public, and none was designed for this evaluation:
- TPC-H (10 cases). The decision-support benchmark of a wholesale
supplier: orders, line items, customers, parts and suppliers. Synthetic
data at scale factor 0.1. All 8 tables, from the 5 rows of
regionto the 600 572 oflineitem, plus the whole schema as one message and orders with their line items nested inside. - TPC-DS (24 cases). The decision-support benchmark of a retailer: all 24 tables at scale factor 0.1, from 1 row to 288 464. Its tables are wider than TPC-H's, and most of their columns are nullable.
- Public BI (46 cases). Real tables behind 46 public Tableau workbooks, collected by CWI. Real data is skewed and repeats itself, which synthetic data does not. One table per workbook, each a random sample of 350 up to 16 384 rows, in steps of 350, so the cases cover the sizes a response has.
- SchemaStore (27 documents, of which colbin carries 25). Small
configuration files, such as a
package.json, an ESLint configuration or a GitHub workflow, from the corpus of Viotti and Kinderkhedia's JSON size benchmark. They hold almost no table rows, so this dataset measures colbin as a row format. It is the "single records" column above.
A slice of structs is written as rows below 8 elements and as columns from 8 up. The figure takes one table, cuts it to its first 1, 2, 4, … rows and decodes each cut. The schema and the data are the same at every point, and only the row count moves.
Nanoseconds per row to decode (lower is better; both axes are logarithmic):
rows of lineitem |
1 | 4 | 8 | 16 | 64 | 512 | 16 384 | 524 288 |
|---|---|---|---|---|---|---|---|---|
| colbin | 512 | 326 | 318 | 249 | 202 | 164 | 132 | 90 |
| vtprotobuf | 381 | 324 | 311 | 303 | 309 | 288 | 221 | 215 |
| msgpack, generated | 421 | 333 | 320 | 317 | 326 | 308 | 261 | 254 |
| Arrow | 17 958 | 4 660 | 2 419 | 1 307 | 484 | 202 | 138 | 123 |
| JSON | 1 899 | 1 680 | 1 622 | 1 587 | 1 620 | 1 565 | 1 496 | 1 490 |
- Below 8 rows colbin writes the rows one after another, as the row formats do, and costs about what they cost. At one row it decodes 1.3× slower than vtprotobuf, and it is level by four rows.
- From 8 rows the slice is a table. Its header and one descriptor per
column are a fixed cost, paid once and spread over the rows. A row
format's cost per row stays nearly flat while colbin's keeps falling: on
lineitemit is 1.2× faster than vtprotobuf at 16 rows, 1.5× at 64, 1.7× at 16 384 and 2.4× at 524 288. On Bimbo, a table of numbers, it is 1.7× at 64 rows and 2.2× at 16 384. - The cost of the switch shows at exactly 8 rows on Bimbo, where the fixed cost is paid over only eight rows (1.4× slower than vtprotobuf). It is recovered by 16.
- Arrow is columnar with a larger fixed cost. It is 35× slower than
colbin at one row of
lineitemand keeps improving after colbin levels off. On Bimbo it overtakes colbin between 256 and 512 rows and is 2.8× faster at 16 384. Onlineitem, which has strings, colbin stays ahead at every size.
The same trend holds across the 107 cases of the evaluation, each with its own schema. colbin's decode against vtprotobuf's, by the rows of the message:
| rows | 1 | 2–7 | 8–30 | 350–2 000 | 2 000–8 000 | 8 000–16 384 | over 16 384 |
|---|---|---|---|---|---|---|---|
| against vtprotobuf | 1.02× | 1.01× | 1.50× | 1.90× | 1.88× | 2.8× | 2.7× |
| against JSON | 3.7× | 3.9× | 4.9× | 8.4× | 10.2× | 17.8× | 19.6× |
A row format allocates as it meets each row and each string, so its allocations grow with the rows. colbin decodes a table column by column:
- Allocations. Decoding
lineitemtakes 8 allocations at any size from 8 to 4 096 rows, 26 at 16 384 and 772 at 524 288. vtprotobuf takes 4 per row and generated msgpack 3 per row: 2.1 million and 1.6 million. No case of the evaluation, of up to 870 000 rows, takes colbin more than two thousand allocations to decode. - Bytes. Every decoder has to hold the same data, so the bytes are close. Decoding 524 288 rows allocates 98 MB with colbin, msgpack or Arrow, 142 MB with vtprotobuf and 433 MB with JSON.
Over all the cases, times fewer than each format to decode into a fresh
value, as bytes / allocations:
| colbin against | bulk tables | web tables | single records |
|---|---|---|---|
| JSON | 3.4× / 932× | 1.79× / 198× | 0.85× / 1.06× |
| MessagePack, generated | 1.00× / 2 487× | 0.86× / 303× | 0.90× / 1.56× |
| Protocol Buffers, vtprotobuf | 1.45× / 3 276× | 1.08× / 380× | 2.5× / 2.4× |
| FlatBuffers | 1.12× / 3 186× | 0.91× / 372× | 0.90× / 1.58× |
| Arrow | 1.00× / 3 233× | 1.34× / 479× | n/a |
| Avro | 3.5× / 253× | 1.82× / 113× | 0.88× / 0.70× |
Three things to keep in mind when reading these:
- The allocations a row format makes come from strings and from rows held behind pointers. On a table of numbers only, such as Bimbo, generated msgpack decodes in 2 allocations, as few as colbin.
- Each library decodes into the type it decodes into. Protocol Buffers' Go binding holds a repeated message as a slice of pointers, one allocation per row, so part of that gap is the binding and not the wire format.
- Encoding into a reused buffer, generated msgpack and Protocol Buffers never allocate. colbin allocates nothing in 89 of its 105 cases and at most 9 times in the others, all of them tables of more than 2.5 MB.
colbin does not read a field without decoding the message, which Arrow and FlatBuffers do: summing one column in place costs them a small fraction of a decode. An application that reads one field of a large message and discards the rest is better served by those formats.
The whole evaluation was measured again on a Ryzen 7 5700U with its clock fixed: an earlier microarchitecture, about half the clock and a 4 MB cache. The sizes came out the same byte for byte, and the conclusions are the same. The margins move, and not all one way:
colbin against, encode / decode |
bulk tables | web tables | single records |
|---|---|---|---|
| JSON | 23.1× / 30.1× | 13.9× / 16.4× | 2.8× / 2.3× |
| MessagePack, generated | 1.51× / 3.8× | 1.28× / 2.8× | 0.90× / 0.91× |
| Protocol Buffers, vtprotobuf | 1.96× / 3.4× | 1.29× / 2.4× | 0.92× / 0.99× |
The npm package decodes a table into a flat typed buffer in WebAssembly. A row
builder, generated per field signature and cached, then turns that buffer into
objects, so no JSON text is produced or parsed. Measured on 1 000 product
records under Node 24 (bun run bench in js/):
| wire | gzip | to objects | |
|---|---|---|---|
JSON + JSON.parse |
106 670 B | 12 124 B | 0.32 ms |
colbin + codec.unmarshal |
30 413 B | 3 182 B | 0.16 ms |
git clone https://github.com/ivanjoz/colbin-benchmarks && cd colbin-benchmarks
./reproduce.sh # fetches and verifies the datasets, measures, writes the tablesA quick comparison of three formats on two cores:
datasets/fetch-all.sh
go run ./cmd/colbinbench -cases all -formats colbin,msgpack,vtprotobuf \
-ops encode,decode-fresh,decode-reuse -count 5 -cores 0,2Comparative benchmarks live in that repository so that colbin's go.mod stays
free of protobuf and msgpack. PERFORMANCE.md keeps the
earlier, local measurements and the optimization history.
- A field's type is not on the K4 wire. A reader steps over a field it does not know, but a field whose type changed under the same id is read as the new type. Give a changed field a new id.
- Untagged ids depend on field names and declaration order, as described under Field ids.
- Not supported yet: fixed-size arrays, slices of slices other than
[][]byte, interfaces with methods (a protobufoneof),map[any]T,map[bool]any,map[K]*scalarand map values nested deeper than a slice (map[K][][]T,map[K][]*T).intanduintare encoded as 64-bit. - An empty slice and a nil slice are the same on the wire. Both decode as nil, and a pointer to an empty slice decodes as a nil pointer.
- No compatibility promise across minor versions while on
0.x. Every side must run the same version, and a mismatch shows up as corrupt data rather than a version error. - Known implementation gaps are listed in INTERNALS §20. For example, the Rust derive does not write maps of structs or of slices.
- Field ids stop at 4080. A protobuf field number above that has to be renumbered.
| location | notes | |
|---|---|---|
| Go | the repository root | the reference implementation: reflection codec, Codec[T], code generator, schema section, JSON rendering |
| Rust | rust/ |
#[derive(Colbin)] emits straight-line encode and decode; JSON → colbin encoder with schema inference (rust/ENCODER.md) |
| JavaScript | js/, npm colbin |
the Rust crate compiled to WebAssembly; decodes to objects, columns or JSON text, encodes from JSON |
#[derive(Colbin)]
struct Charge {
#[cb(1)] company_id: u32,
#[cb(2)] note: String,
}
let message = charge.encode();
let back = Charge::decode(&message)?;import { Codec } from 'colbin'
const codec = await Codec.open()
codec.setSchema(section)
const rows = codec.unmarshal(message)The implementations are pinned to each other with test corpora that Go writes:
- Rust decodes Go's bytes, encodes the same bytes from the same values, and renders every document walk to Go's exact JSON.
- JavaScript does the same for every type in its corpus, and refuses every single-byte corruption that Go refuses.
- CI regenerates each corpus and fails on any difference.
colbin is used in Genix, a self-hostable ERP and e-commerce platform:
- Backups. Tenant data exports, one
.colbin.zstdentry per batch of table rows. - genix-orm. Struct, slice and map columns stored as colbin blobs in ScyllaDB, and whole records in DynamoDB.
- Configuration and sessions. The per-company configuration document, and the session token.
- Next: responses from the Genix backend to its frontend, through the npm package.
Two more projects use it:
- fareward, inside Genix: framing
between the Go client and the Rust services (credits, locks, budgets, the
request log). Go uses
Codec[T]and Rust uses#[derive(Colbin)]. - genix-search: query requests and responses.
INTERNALS.md |
the format bit by bit, the Go codec, the Rust crate, the WebAssembly module, the npm package, cross-language testing and release |
RATIONALE.md |
the decisions and the measurements behind them, including reverted ones |
rust/README.md |
the Rust crate and its derive |
rust/ENCODER.md |
encoding JSON to colbin: inference, refusals, warnings |
js/README.md |
the npm package |
| colbin-benchmarks | the comparative benchmarks and the pinned datasets |