xpatch
A high-performance delta compression library with automatic algorithm selection.
Features
- Automatic Algorithm Selection: Analyzes changes and chooses the best compression strategy
- Excellent Compression: 99.4-99.8% average space savings on real-world code changes
- Fast Performance: 40-55 GB/s throughput for typical changes, <1 µs decoding
- Optional zstd Compression: Additional compression layer for complex changes
- Metadata Support: Embed version tags with zero overhead for values 0-15
- Multi-language: Also available for Python and Node.js
Installation
[]
= "0.3.1"
Requirements:
- Rust edition 2024 or later (Rust 1.92.0+)
Quick Start
use delta;
API
encode
Creates a delta that transforms base_data into new_data.
tag: User-defined metadata value (tags 0-15 use zero overhead)base_data: The original datanew_data: The target dataenable_zstd: Enable zstd compression for complex changes (slower but better compression)
Returns: Compact delta as bytes
decode
Applies a delta to reconstruct the new data.
base_data: The original data the delta was created fromdelta: The encoded delta
Returns: Reconstructed data or error
get_tag
Extracts the tag value from a delta without decoding it.
Returns: Tag value or error
CLI Tool
Install the CLI tool with:
Usage:
# Create a delta
# Apply a delta
# Show delta info
Performance
Tested on 1.2+ million real-world git changes:
- Code repositories: 2 bytes median (99.8% space saved)
- Documentation: 23 bytes median (99.4% space saved)
- Encoding: 10-208 µs depending on optimization mode
- Decoding: <1 µs (effectively instant)
How It Works
xpatch analyzes the change pattern and automatically selects the most efficient algorithm:
- Change Analysis: Detects whether the change is a simple insertion, removal, or complex modification
- Pattern Detection: Identifies repetitive patterns that can be compressed efficiently
- Algorithm Selection: Tests multiple specialized algorithms and chooses the smallest output
- Encoding: Creates a compact delta with algorithm metadata in the header
For complex changes, xpatch uses gdelta, a general-purpose delta compression algorithm, with optional zstd compression.
Examples
See the examples directory:
Run examples with:
Benchmarks
Run the comprehensive benchmark suite:
# Quick stress tests
# Real-world git repository benchmarks
XPATCH_PRESET=tokio
Related Projects
- xpatch repository - Multi-language bindings and documentation
- gdelta - General-purpose delta compression
- xpatch Demo Editor - Live demo
License
Dual-licensed under AGPL-3.0-or-later or commercial license. See LICENSE-AGPL.txt and LICENSE-COMMERCIAL.txt.
For commercial licensing inquiries: xpatch-commercial@alias.oseifert.ch