| Crates.io | cydec |
| lib.rs | cydec |
| version | 0.0.4 |
| created_at | 2025-10-20 18:04:29.454204+00 |
| updated_at | 2025-10-20 18:34:34.83471+00 |
| description | High-performance compression library for numerical time series data using delta encoding, zigzag encoding, and LZ4 |
| homepage | https://github.com/tia-lab/cydec |
| repository | https://github.com/tia-lab/cydec |
| max_upload_size | |
| id | 1892437 |
| size | 195,361 |
A straightforward compression library for numeric data in Rust, designed with database and time-series applications in mind.
cydec provides efficient compression for numeric arrays (integers and floating-point numbers) using a combination of well-established techniques:
The result is typically 2-10x compression ratios for sorted or time-series numeric data, with very fast compression and decompression speeds.
This library works best for:
It may not be the best choice for:
use cydec::{IntegerCodec, FloatingCodec};
use anyhow::Result;
fn main() -> Result<()> {
// Compress integers
let codec = IntegerCodec::default();
let data: Vec<i64> = vec![100, 102, 105, 110, 115, 120];
let compressed = codec.compress_i64(&data)?;
let decompressed = codec.decompress_i64(&compressed)?;
assert_eq!(data, decompressed);
// Compress floating-point numbers
let float_codec = FloatingCodec::default();
let float_data: Vec<f64> = vec![1.0, 1.1, 1.2, 1.3, 1.4];
let compressed = float_codec.compress_f64(&float_data, None)?;
let decompressed = float_codec.decompress_f64(&compressed, None)?;
Ok(())
}
i64 / u64 - 64-bit integersi32 / u32 - 32-bit integersi16 / u16 - 16-bit integersi8 / u8 - 8-bit integersf64 - 64-bit floats (9 decimal places precision by default)f32 - 32-bit floats (6 decimal places precision by default)You can adjust the precision/scale factor for floating-point compression based on your needs.
The library includes parallel compression variants for large datasets:
let codec = IntegerCodec::default();
let large_data: Vec<i64> = (0..1_000_000).collect();
// Compress in parallel chunks
let compressed = codec.par_compress_i64(&large_data, 10_000)?;
let decompressed = codec.par_decompress_i64(&compressed)?;
The compressed format includes a small header (15-23 bytes) containing:
Benchmarked on the following hardware:
| Data Type | Compression | Decompression |
|---|---|---|
| i64 | 1.33 GiB/s | 880 MiB/s |
| u64 | 1.42 GiB/s | 850 MiB/s |
| i32 | 829 MiB/s | 396 MiB/s |
| u32 | 942 MiB/s | 396 MiB/s |
| f64 | 571 MiB/s | 334 MiB/s |
| Data Pattern | Elements | Ratio |
|---|---|---|
| Sequential i64 | 1M | 2023x |
| Sequential i64 | 100K | 1882x |
| Sequential i64 | 10K | 1111x |
| Sequential i64 | 1K | 222x |
| Stock prices (real) | 100K | 1.6x |
| Sensor readings | 1M | 2.0x |
| Timestamps | 1M | 1015x |
| Database IDs (gaps) | 100K | 1878x |
| Sparse (95% zeros) | 100K | 1000x |
The library prioritizes speed over maximum compression. If you need better compression ratios and can accept slower speeds, consider using zstd or similar algorithms.
This library is functional but still evolving. The API may change in future versions. Currently tested on:
Contributions, bug reports, and feature requests are welcome.
Dual licensed under MIT OR Apache-2.0. Choose whichever license works best for your project.
Built on top of excellent Rust crates:
integer-encoding for variable-length integerslz4_flex for LZ4 compressionrayon for parallel processinganyhow for error handlingThe compression techniques used here are industry-standard approaches, not novel inventions. This library simply packages them in a convenient, Rust-native way for numeric data compression.