Skip to main content

Crate base122_fast

Crate base122_fast 

Source
Expand description

§Base122-Fast

A high-performance Base122 implementation achieving throughput up to 4.1 Gbps (encoding) and 4.8 Gbps (decoding) on modern hardware (e.g., AMD Ryzen 5 5600, single-threaded).

Base122 is a binary-to-text encoding scheme that is significantly more space-efficient than Base64, offering approximately 14% overhead compared to Base64’s 33%, while remaining valid UTF-8.

§Performance

This crate is engineered for maximum throughput using several low-level optimizations:

  • SWAR (SIMD Within A Register): Processes 64-bit words using bitwise masks to detect illegal characters across multiple bytes simultaneously, minimizing per-byte overhead.
  • Branchless Fast-Paths: Efficiently skips escape-character checks for ASCII-compatible segments.
  • Zero-Copy Strategy: Utilizes direct pointer arithmetic and pre-allocated buffers to minimize allocations.
  • Unsafe Intrinsic Speed: Leverages unsafe Rust for unchecked memory access and optimized bit manipulation.

§Quick Start

let data = b"hello world";
let encoded = encode(data);
let decoded = decode(&encoded).expect("Failed to decode");
assert_eq!(data, decoded.as_slice());

Functions§

decode
Decodes a Base122 encoded string back into its original binary form.
encode
Encodes binary data into a Base122 string.