| Crates.io | gdelta |
| lib.rs | gdelta |
| version | 0.2.1 |
| created_at | 2025-12-04 19:30:21.41574+00 |
| updated_at | 2025-12-11 13:05:57.015776+00 |
| description | Fast delta compression algorithm for similar data chunks |
| homepage | https://github.com/ImGajeed76/gdelta |
| repository | https://github.com/ImGajeed76/gdelta |
| max_upload_size | |
| id | 1966911 |
| size | 261,945 |
A fast delta compression algorithm for similar data chunks, implemented in pure Rust.
gdelta is a Rust implementation of the GDelta algorithm by Haoliang Tan. It provides efficient delta encoding for
similar data chunks (typically 4KB - 64KB) commonly found in deduplication systems.
Key Features:
Performance:
Benchmarked on AMD Ryzen 7 7800X3D with 16 cores (Fedora Linux 42). See PERFORMANCE.md for detailed analysis.
Add this to your Cargo.toml:
[dependencies]
gdelta = "0.2"
Install using cargo:
cargo install gdelta --features cli
Or build from source:
git clone https://github.com/ImGajeed76/gdelta
cd gdelta
cargo build --release --features cli
# Binary at: target/release/gdelta
use gdelta::{encode, decode};
// Create base data and modified version
let base_data = b"Hello, World! This is some base data.";
let new_data = b"Hello, Rust! This is some modified data.";
// Encode the delta
let delta = encode(new_data, base_data)?;
println!("Delta size: {} bytes", delta.len());
// Decode to recover the new data
let recovered = decode(&delta, base_data)?;
assert_eq!(recovered, new_data);
Use
gdelta helpto see the most up-to-date options and descriptions.
The CLI provides a simple interface for creating and applying delta patches:
Create a delta patch:
# Basic usage
gdelta encode old_file.bin new_file.bin -o patch.delta
# With compression (recommended)
gdelta encode old_file.bin new_file.bin -o patch.delta -c zstd
gdelta encode old_file.bin new_file.bin -o patch.delta -c lz4
# With verification
gdelta encode old_file.bin new_file.bin -o patch.delta --verify
Apply a delta patch:
# Auto-detects compression format
gdelta decode old_file.bin patch.delta -o new_file.bin
# Force specific format (if magic bytes conflict)
gdelta decode old_file.bin patch.delta -o new_file.bin --format zstd
Options:
-c, --compress <FORMAT> - Compression: none, zstd, lz4 (default: none)-v, --verify - Verify delta after creation (encode only)-y, --yes - Skip memory warning prompts-f, --force - Overwrite existing files-q, --quiet - Suppress output except errorsExample workflow:
# Create compressed delta
gdelta encode database-v1.db database-v2.db -o update.delta -c zstd
# Later, apply the update
gdelta decode database-v1.db update.delta -o database-v2-restored.db
# Verify the result
diff database-v2.db database-v2-restored.db
Memory Management:
The CLI monitors memory usage and warns when operations might use >80% of available RAM. This is important because gdelta loads entire files into memory.
# For large files, the tool will prompt:
⚠ Memory warning: This operation requires ~12.4 GB
Available: 8.2 GB free (16 GB total)
Continue? [y/N]:
Use -y to skip prompts in automated scripts.
GDelta uses:
The algorithm identifies matching regions between base and new data, then encodes only the differences as a series of copy and literal instructions.
The implementation uses optimized default parameters:
These parameters are tuned for typical deduplication workloads.
Performance Comparison (from comprehensive benchmarks):
| Algorithm | Speed | Compression | Memory | Use Case |
|---|---|---|---|---|
| gdelta | 397 MB/s | 63% | Low | Best all-around speed |
| gdelta+zstd | 258 MB/s | 70% | Low | Balanced speed/compression |
| gdelta+lz4 | 350 MB/s | 66% | Low | Fast with compression |
| xpatch | 291 MB/s | 75% | Low | Automatic algorithm selection |
| qbsdiff | 22 MB/s | 84% | Medium | Maximum compression |
| xdelta3 | 45 MB/s | 81% | Medium | Failed verification ⚠️ |
See PERFORMANCE.md for detailed benchmarks and methodology.
Key Takeaways:
# Run unit tests
cargo test
# Run integration tests
cargo test --test '*'
# Run CLI test suite
./test_gdelta.sh
# Run simple benchmarks (quick verification)
cargo bench --bench simple
# Run comprehensive benchmarks (15-30 min)
cargo bench --bench comprehensive
# Run comprehensive benchmarks with custom filters
BENCH_FORMATS=json,csv BENCH_ALGOS=gdelta,xpatch cargo bench --bench comprehensive
The comprehensive benchmark supports two modes:
# Quick mode (default): smaller sample size, faster
BENCH_MODE=quick cargo bench --bench comprehensive
# Full mode: larger sample size, more accurate
BENCH_MODE=full cargo bench --bench comprehensive
Results are saved to target/benchmark_report_<timestamp>.md and .json.
This is a Rust implementation of the GDelta algorithm by Haoliang Tan.
Original repositories/resources:
This project is licensed under the MIT License - see the LICENSE file for details.
Contributions are welcome! Please feel free to submit a Pull Request.
Built with ❤️ by ImGajeed76