Bincode-Next
Bincode-Next is a high-performance binary encoder/decoder pair that uses a zero-fluff encoding scheme. It is a modernized fork of the original bincode library, maintained by the Apich Organization to ensure continued development and extreme performance optimizations for the Rust ecosystem.
The size of the encoded object will be the same or smaller than the size that the object takes up in memory in a running Rust program.
Key Features
- Performance: Leverages SIMD (SSE2 on x86_64, NEON on AArch64) for rapid varint scanning and bulk primitive copying for massive throughput.
- Zero-Copy: Nested zero-copy support via Relative Pointers and const alignment. (optional
zero-copyfeature) - Bit-Packing: Bit-level packing for space-optimized serialization. (
BitPackedderive +config.with_bit_packing()) - Schema Fingerprinting: 64-bit schema hash covering field names, types, order, and full configuration — format changes (Bincode vs CBOR), endianness, integer encoding, and CBOR options all produce distinct fingerprints. (
Fingerprintderive +config.with_fingerprint()) - Compile-time Memory Bounds:
StaticSizegives a worst-case byte bound at compile time;PACKED_MAX_SIZEgives the tighter bound when bit-packing is active. (static-sizefeature) - CBOR Format: Full RFC 8949 CBOR encoding/decoding with deterministic modes. (
config.with_cbor_format()) - Async Fiber Decoding: Zero-cost async decoding via Unified Fiber-backed Async (UFA). (
async-fiberfeature) - Stream Support: Works seamlessly with
std::io(Reader/Writer) andno_stdenvironments.
Getting Started
Add bincode-next to your Cargo.toml:
[]
= "3.0.0-rc.15"
Basic Encode / Decode
use ;
;
Serde Compatibility
Bincode-Next works with any type that already derives serde::Serialize /
serde::Deserialize — no need to re-derive Encode/Decode at all. Enable the
serde feature and use the bincode_next::serde::* entry points.
[]
= { = "3.0.0-rc.14", = ["serde"] }
= { = "1", = ["derive"] }
#
You can also mix: derive both Serialize and Encode on the same type, then use
#[bincode(with_serde)] on individual fields to route specific fields through their
serde impl (useful for types that only implement Serialize, not Encode).
Bit-Packing
Enable bit-packing in your configuration to pack fields at bit granularity. Consecutive
#[bincode(bits = N)] fields share bytes — 3 bits + 5 bits = exactly 1 byte on the wire.
use ;
Zero-Copy Structures
The zero-copy feature lets you build flat byte blobs that can be accessed as typed
Rust references without any deserialization step — ideal for memory-mapped files,
shared memory, and IPC.
#[derive(ZeroCopy)] on a #[repr(C, u8)] enum generates a companion *Builder
type that mirrors every variant. Use ZeroBuilder to accumulate bytes, reserve::<T>()
to claim space, and build_to_target() to write and get back a live typed reference
directly into the buffer.
use ;
/// Packet layout stored verbatim in the byte blob.
For lower-level use, RelativePtr<T, OFFSET_SIZE> lets you embed self-relative
pointers inside any #[repr(C)] struct:
use ;
;
Compile-time Memory Bounds (StaticSize)
StaticSize gives a compile-time upper bound on encoded size — useful for stack
allocation and no_std fixed-size buffers. Enable with the static-size feature.
MAX_SIZE assumes worst-case varint encoding; PACKED_MAX_SIZE is tighter when
bit-packing is active (consecutive #[bincode(bits = N)] fields share bytes).
use ;
Schema Fingerprinting
Fingerprinting embeds a 64-bit schema hash into each encoded message. The hash covers
field names, types, ordering, and the full configuration — including format
(Bincode vs CBOR), endianness, integer encoding, and all CBOR options. Any mismatch
between encoder and decoder returns a DecodeError::SchemaHashMismatch.
use ;
// Adding a field changes the schema hash → decode_from_slice returns an error
CBOR Format
Bincode-Next implements full RFC 8949 CBOR encoding. Switch formats with a single config call; all existing derives work unchanged.
use ;
Async Fiber Decoding
Bincode-Next supports true zero-cost asynchronous decoding using Unified Fiber-backed
Async (UFA). Synchronous Decode traits run on a dedicated lightweight fiber stack,
avoiding state-machine code generation overhead entirely.
use ;
async
Performance Optimizations
Bincode-Next includes advanced optimizations for extreme performance:
- SIMD Varint Scanning: Accelerates decoding of collections (like
Vec<u64>) by scanning for small values using SSE2 or NEON instructions. - Bulk Native Copy: Automatically detects when data can be copied directly from memory (e.g., slices of primitives with matching endianness) to avoid element-wise processing.
- Uninitialized Memory: Utilizes
MaybeUninitandset_lenoptimizations forVecdecoding to avoid redundant zero-initialization.
git clone https://github.com/Apich-Organization/bincode.git
cd bincode
cargo bench --bench extreme_perf
cargo bench --bench complex
TL;DR: Please visit https://bincode-next.apich.org/ for more detailed information.
Performance Comparison: Decoding
Baseline: bincode-next (traits, varint) at 16.878 µs
| Rank | Implementation | Interface | Int Encoding | Median Time | Relative Speed |
|---|---|---|---|---|---|
| 1 | bincode-next | traits | varint | 16.878 µs | 1.00x |
| 2 | bincode-next | traits | fixed | 21.872 µs | 1.30x |
| 3 | bincode-v2 | serde | fixed | 21.973 µs | 1.30x |
| 4 | bincode-v1 | serde | N/A | 22.074 µs | 1.31x |
| 5 | bincode-v2 | serde | varint | 25.727 µs | 1.52x |
Performance Comparison: Encoding
Baseline: bincode-next (traits, fixed) at 2.9350 µs
| Rank | Implementation | Interface | Int Encoding | Median Time | Relative Speed |
|---|---|---|---|---|---|
| 1 | bincode-next | traits | fixed | 2.9350 µs | 1.00x |
| 2 | bincode-v1 | serde | N/A | 3.0767 µs | 1.05x |
| 3 | bincode-v2 | serde | fixed | 3.3295 µs | 1.13x |
| 4 | bincode-next | traits | varint | 3.3467 µs | 1.14x |
| 5 | bincode-v2 | serde | varint | 4.2489 µs | 1.45x |
Efficiency Score: Combined Round-Trip Performance
Sum of Median Decode + Median Encode (Normalized to the fastest = 1.00x)
| Rank | Implementation | Interface | Int Encoding | Total Time | Efficiency Score |
|---|---|---|---|---|---|
| 1 | bincode-next | traits | varint | 20.225 µs | 1.00x |
| 2 | bincode-next | traits | fixed | 24.807 µs | 1.23x |
| 3 | bincode-v1 | serde | N/A | 25.151 µs | 1.24x |
| 4 | bincode-v2 | serde | fixed | 25.303 µs | 1.25x |
| 5 | bincode-v2 | serde | varint | 29.976 µs | 1.48x |
Vector u64 Decoding: Varint Performance
Contrasting small vs. large integer varint decoding.
| Dataset | Implementation | Median Time | Relative Speed |
|---|---|---|---|
| Small Varint | bincode-next (current) | 2.8256 µs | 1.00x |
| Small Varint | bincode-v2 (original) | 12.450 µs | 4.41x |
| Large Varint | bincode-next (current) | 13.062 µs | 1.00x |
| Large Varint | bincode-v2 (original) | 17.635 µs | 1.35x |
Vector u64 Decoding: Fixed Performance
Baseline: bincode-next (current) at 1.8373 µs
| Rank | Implementation | Median Time | Relative Speed |
|---|---|---|---|
| 1 | bincode-next (current) | 1.8373 µs | 1.00x |
| 2 | bincode-v1 | 7.5378 µs | 4.10x |
| 3 | bincode-v2 (original) | 10.129 µs | 5.51x |
Bulk u8 Decoding: Throughput Performance
Baseline: bincode-next (current) at 160.44 ns
| Rank | Implementation | Median Time | Relative Speed |
|---|---|---|---|
| 1 | bincode-next (current) | 160.44 ns | 1.00x |
| 2 | bincode-v2 (original) | 273.86 ns | 1.71x |
| 3 | bincode-v1 | 6307.00 ns | 39.31x |
About Security and Code Quality
For security issues, please visit the Security Team Homepage for more details on reporting.
All code tests passed miri and all main crate source code passed clippy without errors.
MIRIFLAGS="-Zmiri-disable-isolation" cargo +nightly miri test --all-features --no-fail-fast
cargo clippy --all-features
We remain committed to code security and welcomed security reporting.
And please notice that contributors shall follow the community guide lines of bincode-next.
Specification
The formal wire-format specification is available in docs/spec.md.
FAQ
Why Bincode-Next?
Bincode-Next was created to continue the legacy of the original Bincode project while pushing the boundaries of what's possible with modern Rust performance techniques and AI-assisted development.
Is it compatible with Bincode 1.x / 2.x?
Yes, Bincode-Next is designed to be wire-compatible with Bincode 2.x when using the same configurations. It also supports legacy 1.x formats via configuration.
Contributing
We welcome contributions! Please see CONTRIBUTING.md for more details.
License
Bincode-Next is licensed under either of:
- The MIT License (MIT)
- The Apache License, Version 2.0
See LICENSE.md for details.