Architecture
Specifications describe how the implementation works today: ownership, APIs, data flow, state transitions, SIMD dispatch, errors and known gaps. To use the crate, read the guides instead; for checks and repository layout, see development.
Where to start
| You want to understand | Read, in order |
|---|---|
| What a frame looks like on the wire | Frame format |
How a compress call becomes a frame | Compressor → Compression graphs → Standard graphs → Encoder codecs |
| How a frame is decoded | Decompressor → Decoder codecs |
| How a codec family works | Entropy coders, LZ codecs and graphs, Transformer, ML selector and clustering, SDDL and SDDL2 |
| How applications extend the codec set | Custom codecs → Dictionaries |
| How one input is split across threads | Parallel compression |
| How containers work | Framed containers |
| How byte identity is established | Compatibility → Fuzzing |
| Which features compile which code | Codec features |
Specifications share an outline: module and ownership boundaries, public surface, control and data flow with Mermaid diagrams, and error propagation. What is missing or slower than the reference is listed under known gaps.
Module map
graph TD
Root[mopenzl public facade] --> Encode[compressor: compression feature]
Root --> Decode[decompressor: decompression feature]
Root --> Framed["framing: opt-in framed resource containers"]
Framed --> FCore["private framing::core: resource assembly, units, directory"]
FCore --> Encode
FCore --> Decode
Root --> GraphApi["graph, input: graph builder, typed inputs (compression)"]
Root --> Custom["custom_codec: application callbacks, signatures and contexts"]
Custom --> ECore
Custom --> DCore
Root --> DictApi["dict: Dict, DictBundle, BundleStore"]
Root --> Common[Backend, RetentionPolicy, FormatVersion, DataType, io]
Encode --> Parallel["parallel: caller-scheduled tasks, batches, streams (std)"]
GraphApi --> Parallel
Parallel --> PCore[private parallel::core: workers, staging, ordered assembly]
PCore --> ECore
Encode --> Dest[shared::destination: initialized or MaybeUninit output]
Decode --> Dest
GraphApi --> Reg
Encode --> ECore[private compressor::core]
Decode --> DCore[private decompressor::core]
ECore --> EStream[core::stream: session state machine]
ECore --> EChunk[core::chunk + core::frame: specialized default-graph writer]
ECore --> EZstd[core::zstd: Zstandard node]
ECore --> EGraph[core::exec + layout + rtgraph: graph engine]
EGraph --> Reg["core::registry: 85 nodes, 90 graphs, dict state"]
Reg --> ECodecs["core::codecs: every node encoder, one module per feature"]
Reg --> EGraphs["core::graphs: standard graphs, selectors, segmenters"]
EGraphs --> Special["transformer, ml_selector, clustering, sddl, sddl2, entropy, lz"]
DCore --> DStream[core::stream: unit assembly]
DCore --> DChunk[core::chunk: chunk graph layout]
DCore --> DZstd[core::zstd: magicless Zstandard decoder]
DCore --> DCodecs[core::codecs: every standard codec, one module per feature]
DCore --> DData[core::data: typed streams]
EChunk --> Shared[private shared]
ECodecs --> Shared
EGraphs --> Shared
DChunk --> Shared
DCodecs --> Shared
Shared --> Prims["wire, varint, bitpack, xxh3, sha256, dictwire"]
Shared --> Algo["entropy, stats, estimate, numeric, bitpack_kernels, byte_transpose, cbor"]
Prims --> SIMD[fearless_simd: selected backend]
ECodecs --> SIMD
DCodecs --> SIMD
EZstd --> Mzstd[mzstd: safe-Rust zstd 1.5.7]
DZstd --> Mzstd
C[openzl-ffi: OpenZL v0.3.0 C] -. tests and benchmarks .-> Root
Public modules own ergonomic configuration and high-level errors. Private core
modules own algorithms and state machines; implementation errors, SIMD types and
mzstd types do not appear in public signatures. Each codec compiles
independently.
SIMD dispatch boundary: the fearless_simd::Level is chosen once per
Compressor / Decompressor (its Backend) and reaches every node encoder
as NodeCx::simd and every codec decoder as State::simd. Each codec
dispatches on it once per stream (PivCo-Huffman once per tree node) and runs
monomorphized kernels inside the dispatched function; every kernel keeps a
scalar baseline that tests compare at each level the host offers.
Common boundaries
The wire format, feature gates and primitives both directions share.
| Specification | Scope |
|---|---|
| Frame format | Magic, frame header, chunk header lanes, stream numbering, stored streams, checksums and limits as both codecs read and write them. |
| Codec features | Direction and per-codec feature gates, std/no_std, libm and profiling features, and how disabled codecs behave. |
| Shared primitives | Varints, bit packing, wire constants, XXH3 with its SIMD accumulator, and the encoder-side shared modules. |
| Uninitialized output | compress_to_uninit, decompress_to_uninit and process_uninit: BorrowedBuf sinks, zero-free Vec decoding and their Miri/ASan coverage. |
Compression
From the public Compressor to the graph engine and node encoders.
| Specification | Scope |
|---|---|
| Compressor | Public API, the specialized default-graph path, chunking, sinks, the session state machine, graph selection, I/O and errors. |
| Compression graphs | The graph engine: typed streams, runtime graph, contexts, successor order, stores, conversions, trial compression and the registry tables. |
| Standard graphs | The decision logic of every standard graph: routing, stores, segmenters and structure graphs. |
| Encoder codecs | Every node encoder: node ID to codec ID, feature, ports, wire summaries, deviations and gaps. |
| Parallel compression | Caller-scheduled segments, graph/codec builder, source/staging ownership, dictionary-aware frame assembly and deferred streaming output. |
Codec families
Selectors, interpreters and coders with enough machinery for a specification of their own.
| Specification | Scope |
|---|---|
| Entropy coders | OpenZL’s FSE/Huffman fork, PivCo-Huffman, the five entropy nodes and the entropy graph’s plan. |
| LZ codecs and graphs | lz4 (fast, HC, optimal), lz, field_lz, mux_lengths, quantize, the shared lz_common infrastructure and the LZ graphs. |
| Transformer | The numeric selector: features, generated scorers, guards, depth limits, static fallbacks, float determinism and the no_std caveat. |
| ML selector and clustering | Gradient-boosted-tree selection and tag-based clustering with their CBOR configurations. |
| SDDL and SDDL2 | The description interpreter, the bytecode VM, chunking and replay. |
| Custom codecs | Application codec registration, typed and variable ports, callback contexts, custom wire IDs, validation, errors and lifetime. |
| Dictionaries | Dict, DictBundle and BundleStore, wire formats, the encoder and decoder flows. |
Decompression
The universal decoder and its codec catalogue.
| Specification | Scope |
|---|---|
| Decompressor | Frame and unit parsing, chunk graph layout, the typed node executor, typed multi-output decoding, dictionaries, sessions, limits, I/O and errors. |
| Decoder codecs | Every standard codec decoder: signatures, wire formats, invariants and deviations from the reference on malformed data. |
Containers
The opt-in framed container around ordinary frames.
| Specification | Scope |
|---|---|
| Framed containers | Opt-in graph-per-resource containers, typed frames, metadata, bounded native sessions, transport retries and checked seek directories. |
Development tools
How the repository measures, tests and publishes itself.
| Specification | Scope |
|---|---|
| Compatibility | The C oracle and its shims per family, byte-identity and decode differential tests, and what each test file covers. |
| Fuzzing | AFL targets, oracles, regression replay and the libFuzzer adapters. |
| Implementation comparison | Criterion and Silesia harness methodology (standard graphs and custom callbacks against C) and recorded results. |
| Continuous integration | Workflows, feature probes, AFL smoke runs, Miri and AddressSanitizer selection, coverage gate, hotpath reports and releases. |
| Documentation publishing | Source staging, navigation, section pages, recipe execution, link validation and Pages deployment. |
Known gaps (whole crate)
- Scope: every non-legacy OpenZL v0.3.0 node, graph, selector and segmenter is
ported, on both sides. Deprecated nodes 76 to 85 and format versions below 21
are not supported; unregistered custom codecs decode as
Unsupported. - Dictionaries: only Zstandard dictionaries materialize; no training (dictionaries).
- Performance:
fearless_simdkernels cover XXH3, the LZ row-table tag match, PivCo-Huffman (128-bit, plus 512-bit expand/compress on AVX-512), bitpack bit counting, byte transposes and flatpack. FSE, Huffman, LZ4 and the LZ decoders are tuned scalar loops compiled inside the dispatched level. Huffman decoding and the numeric and field_lz graphs remain 0.7 to 0.9× of C on Silesia; LZ4, FSE and Zstandard are within about 10% (comparison). The partition+bitpack decoder fusion is not ported. no_stdbuilds use thelibmcrate for floating point; the Transformer and estimator decisions are byte-identical with the reference only withstd(transformer).- No C ABI crate. Parallel compression supports serial inputs; streaming holds compressed chunks until the total input size is known.
- Verification gaps: no AFL targets for the graph engine, SDDL or CBOR configurations; new SIMD kernels and uninit paths require explicit Miri and ASan selections (fuzzing, CI).