Your serde types, 15× smaller: the columnar serde format in mopenzl
mopenzl 0.2.10 adds a compressed binary serialization format for any Rust type with serde derives. It splits structs, enums, maps and serde_json::Value into typed columns that OpenZL compresses 1.7–2.9× smaller than the same rows written one after another, with no schema files and no code generation.
Summary
- mopenzl 0.2.10 adds an opt-in
serdefeature: a compressed binary format for any type that derivesSerializeandDeserialize. No.protofiles, no code generation, no new types. - Every field, enum tag and
Optionflag becomes its own typed column, and OpenZL compresses each column with codecs made for its type. Timestamps sit next to timestamps, not between strings. - Against the same rows in a bincode-style layout compressed by OpenZL, the output is 1.7–2.9× smaller: 9.51× instead of 5.69× on structured logs, 11.50× instead of 3.96× on numeric samples, 15.12× instead of 8.76× on JSON logs as
serde_json::Value. - On an Apple M-series laptop rows encode at about 170 MB/s and decode at 350–650 MB/s. Rows are cut into self-contained 1 MiB blocks, so any number of them streams in bounded memory.
- Each block carries its schema: fields match by name, fields can be added and removed, numbers widen, and every serde enum representation,
flattenandserde_json::Valueround-trip.#[columns]adds protobuf-style field numbers and a codec per field.
Most of the data we compress is not a file. It is a Vec<LogLine>, a stream of
events, a batch of sensor readings, a cache of API responses. The usual recipe
is to serialize it with bincode, MessagePack or JSON and run zstd on top.
That recipe throws away half of what a compressor could do. Since mopenzl 0.2.10 you can keep it:
[dependencies]
mopenzl = { version = "0.2", features = ["serde"] }
let container = encoder.compress_rows(&rows, BlockSize::default())?;
let restored: Vec<LogLine> = decoder.decompress_rows(&container)?;
Your types stay the same. The output is a compact binary container, and on our benchmarks it is 1.7 to 2.9 times smaller than the same rows written one after another and compressed by the same OpenZL engine.
The numbers
Three corpora from
benches/framed_serde.rs,
default level. The baseline is the strongest fair comparison we could make: the
same rows in a bincode-style layout (fixed-width little-endian fields,
length-prefixed strings), or the JSON text itself, compressed by the C OpenZL
library as one input.
| Corpus | Raw size | Row-major + OpenZL | mopenzl serde |
|---|---|---|---|
| 100k structured log lines | 6.68 MB | 1.17 MB (5.69×) | 0.70 MB (9.51×) |
| 200k numeric sensor samples | 4.20 MB | 1.06 MB (3.96×) | 0.37 MB (11.50×) |
100k JSON log lines as serde_json::Value |
13.90 MB | 1.59 MB (8.76×) | 0.92 MB (15.12×) |
The baseline is already compressed with a modern format-aware compressor. The gain comes from the layout alone: same engine, same level, different arrangement of the same bytes. On numeric data the difference is almost threefold.
And it is fast. On an Apple M-series laptop rows encode at about 170 MB/s
and decode at 350–650 MB/s of row-major size. 100k log lines go to the
container in 40 ms and come back as Vec<LogLine> in 18 ms.
Why columns win
A row-major format writes a log line like this:
at | level | host | path | status | latency | bytes? | tags... | at | level | host | ...
A compressor sees a timestamp, then an enum, then a string, then another
timestamp 60 bytes later. It can find repeats, but it cannot see that the
timestamps grow by a few milliseconds each time, or that status is 200 in
almost every row.
mopenzl turns the same rows inside out:
at: 1700000000000 1700000000015 1700000000030 ... → deltas, tiny integers
level: 1 1 1 0 1 2 1 ... → one byte each, highly repetitive
host: "web-1" "web-2" "web-1" ... → a handful of distinct strings
status: 200 200 200 404 200 ... → almost constant
bytes?: 1 1 0 1 ... + only the values that exist
tags: lengths + all elements in one stream
Every place in your type becomes one typed OpenZL input: integers and floats
as numeric columns, strings and bytes as string columns, enum variants as a
narrow tag column plus a column per field of each variant, Option as a
presence column plus only the values that are present. Lengths and tags are
narrowed per block to the smallest integer that holds them.
OpenZL then does what it was designed for: it picks codecs per column. Sorted timestamps get delta coding, small integers get packed, low-cardinality strings collapse. A row-major stream cannot give it any of that.
No schema files, no code generation
Protobuf, Cap’n Proto and FlatBuffers make you describe your data twice: once in Rust, once in an IDL, plus a build step to keep them in sync. Parquet and Arrow make you convert your structs into their own column types.
Here you write ordinary Rust:
use mopenzl::framing::serde::{BlockSize, SerdeCompress, SerdeDecompress};
use mopenzl::framing::{FramedCompressor, FramedDecompressor};
use serde::{Deserialize, Serialize};
#[derive(Debug, PartialEq, Serialize, Deserialize)]
enum Status {
Ok,
Failed { code: u16 },
}
#[derive(Debug, PartialEq, Serialize, Deserialize)]
struct Request {
at: u64,
path: String,
status: Status,
#[serde(skip_serializing_if = "Option::is_none", default)]
user: Option<u32>,
}
fn main() -> Result<(), Box<dyn std::error::Error>> {
let requests: Vec<Request> = (0..10_000u64)
.map(|i| Request {
at: 1_700_000_000_000 + i * 15,
path: format!("/api/items/{}", i % 50),
status: if i % 97 == 0 { Status::Failed { code: 503 } } else { Status::Ok },
user: (i % 3 == 0).then_some(i as u32 % 1000),
})
.collect();
let mut encoder = FramedCompressor::new(Default::default())?;
let container = encoder.compress_rows(&requests, BlockSize::default())?;
println!("{} rows -> {} bytes", requests.len(), container.len());
let mut decoder = FramedDecompressor::new(Default::default())?;
let restored: Vec<Request> = decoder.decompress_rows(&container)?;
assert_eq!(restored, requests);
Ok(())
}
That is the whole integration. Two trait imports add compress_value,
compress_rows and rows_writer to the compressor and their counterparts to
the decompressor. Your types still serialize to JSON, YAML or anything else
exactly as before.
Binary, but self-describing
Compact binary formats usually pay for their size with fragility: bincode and postcard store fields by position, so adding a field to a struct breaks every byte you have written before.
Each mopenzl block carries its schema: field and variant names and the type of every column. It costs about 200 bytes per block of 1 MiB and buys you the flexibility of JSON:
- Fields match by name. Add a field with
#[serde(default)], remove one, reorder them: old data still loads into the new type. - Numbers widen. A column written as
u16reads into au32ori64. Lossy conversions are refused, never silently truncated. - All of serde works. Externally, internally and adjacently tagged enums,
#[serde(untagged)],#[serde(flatten)],skip_serializing_if,#[serde(skip)], anddeserialize_any. - Even
serde_json::Value. Schemaless JSON is shredded too: every distinct object key gets its own columns, so 100k JSON log lines compress to 15× instead of 9×. That is the 15.12× row in the table above.
Field numbers and a codec per field
When you want protobuf-style stability, or want to tune a hot field, one attribute does it without touching how other formats see the type:
use mopenzl::framing::serde::columns;
#[columns]
#[derive(Debug, PartialEq, Serialize, Deserialize)]
struct Reading {
#[column(id = 1, codec = "field_lz")]
sensor: u32,
#[column(id = 2)]
celsius: f32,
#[column(id = 3, codec = "zstd")]
note: String,
}
#[column(id = N)] stores the field by number: the block drops the name, and
you can rename the field later without breaking old data.
#[column(codec = "...")] sends that field’s columns to any OpenZL graph: a
standard one like zstd, field_lz or store, or your own registered with
GraphParams::with_name. The rest of the row keeps the default graph, and the
decoder needs no configuration at all.
Streams of any size
Rows are cut into self-contained blocks of about 1 MiB of raw data. Each block is an ordinary OpenZL frame in a framed container, so:
rows_writerandrows_readerstream any number of rows throughstd::io::WriteandReadin bounded memory;- each frame is byte-identical to what Meta’s reference OpenZL produces for the same columns, and the C library decodes it.
It is all safe Rust, like the rest of mopenzl, and the new decoder is covered by the same fuzzing setup as the rest of the crate.
Where it fits
The format shines wherever you have many values of the same type:
- logs and traces: structured log lines, spans, audit events;
- telemetry and metrics: sensor samples, time series, counters;
- event streams and queues: batches of messages before they go to disk or over the network;
- caches and snapshots: a
VecorHashMapof records you persist and reload; - JSON archives:
serde_json::Valuedumps you would otherwise gzip.
Where it does not: a single small message on the wire. A block carries its
schema, and columns need rows to pay off, so for one struct per request
bincode or postcard will be smaller. Rows are also deserialized into owned
values: &str fields cannot borrow from the decoded columns.
Try it
[dependencies]
mopenzl = { version = "0.2.10", features = ["serde"] }
serde = { version = "1", features = ["derive"] }
Take a Vec of your own structs, compress it with your current format and with
compress_rows, and compare the sizes. The
guide to storing serde values
covers the API, and the
columnar layout notes
describe exactly how a value becomes columns.
If your data compresses worse than you expected, or a serde feature does not round-trip, open an issue with a sample. Real-world corpora are the best benchmarks we can get.
Questions
What is the mopenzl serde format?
A binary serialization format for any Rust type that implements serde’s Serialize and Deserialize. Instead of writing values row by row, it stores every place in the type (a field, a sequence’s elements, an enum’s variant, an Option’s flag) as a typed column and compresses the columns with OpenZL. It ships in mopenzl 0.2.10 behind the serde feature.
How much smaller is it than bincode or JSON with compression?
On the project’s benchmark corpora, 1.7–2.9× smaller than the same rows in a bincode-style row-major layout compressed by OpenZL, and 1.7× smaller than JSON text compressed by OpenZL. Against the uncompressed data that is 9.51× for structured logs, 11.50× for numeric samples and 15.12× for JSON logs.
Do I need a schema file or code generation?
No. #[derive(Serialize, Deserialize)] is enough. Each block stores its own schema, with field and variant names and column types, so the data describes itself the way JSON does.
Can I change my structs after data has been written?
Yes. Fields are matched by name, so you can add fields (with #[serde(default)]), remove them, and widen numbers, as with serde_json. With #[column(id = N)] a field is stored by number, like protobuf, and can be renamed without breaking old data.
How fast is it?
On an Apple M-series laptop rows encode at about 170 MB/s and decode at 350–650 MB/s of row-major size. The columns themselves decode at the speed of the C OpenZL library; most of the time goes to building Rust values.
When should I not use it?
For a single small message, a plain format like bincode or postcard is smaller, since a block carries about 200 bytes of schema and column compression needs many rows to pay off. Rows are deserialized into owned values, so zero-copy &str fields are not supported.
Cite this post
Mikhail Panfilov. “Your serde types, 15× smaller: the columnar serde format in mopenzl.” M-Compressors, 6 December 2026. https://m-compressors.github.io/2026/mopenzl-serde-columnar-format/