Home

Awesome

Kanzi

Kanzi is a modern, modular, expandable and efficient lossless data compressor implemented in Go.

Unlike the most common lossless data compressors, Kanzi uses a variety of different compression algorithms and supports a wider range of compression ratios as a result. Most usual compressors do not take advantage of the many cores and threads available on modern CPUs (what a waste!). Kanzi is concurrent by design and uses threads to compress several blocks in parallel. It is not compatible with standard compression formats.

Kanzi is a lossless data compressor, not an archiver. It uses checksums (optional but recommended) to validate data integrity but does not have a mechanism for data recovery. It also lacks data deduplication across files. However, Kanzi generates a bitstream that is seekable (one or several consecutive blocks can be decompressed without the need for the whole bitstream to be decompressed).

For more details, see Wiki and Q&A

See how to reuse the code here: https://github.com/flanglet/kanzi-go/wiki/Using-and-extending-the-code

There is a C++ implementation available here: https://github.com/flanglet/kanzi-cpp

There is Java implementation available here: https://github.com/flanglet/kanzi

Build Status Go Report Card Quality Gate Status Lines of Code Documentation License

Why Kanzi

There are many excellent, open-source lossless data compressors available already.

If gzip is starting to show its age, zstd and brotli are open-source, standardized and used daily by millions of people. Zstd is incredibly fast and probably the best choice in many cases. There are a few scenarios where Kanzi can be a better choice:

Benchmarks

AWS c5a8xlarge: AMD EPYC 7R32 (32 vCPUs), 64 GB RAM

go 1.21.10

Ubuntu 24.04 LTS

Kanzi version 2.3.0

On this machine, Kanzi uses up to 16 threads (half of CPUs by default).

bzip3 and zpaq use 16 threads. zstd uses 16 threads for compression and 1 for decompression, other compressors are single threaded.

The default block size at level 9 is 32MB, severely limiting the number of threads in use, especially with enwik8, but all tests are performed with default values.

silesia.tar

Download at http://sun.aei.polsl.pl/~sdeor/corpus/silesia.zip

CompressorEncoding (sec)Decoding (sec)Size
Original211,957,760
s2 -cpu 160.4940.86886,650,932
Kanzi -l 10.5040.36680,277,212
Lz4 1.9.5 -40.3210.33079,912,419
s2 -cpu 16 -slower1.5170.86879,555,929
Zstd 1.5.6 -2 -T160.1510.27169,556,157
Kanzi -l 20.5330.26368,195,845
Brotli 1.1.0 -21.7490.76168,041,629
Gzip 1.12 -920.091.40367,652,449
Kanzi -l 31.0570.35965,613,695
Zstd 1.5.6 -5 -T160.3560.28963,131,656
Kanzi -l 41.1250.51961,249,959
Zstd 1.5.5 -9 -T160.6900.27859,429,335
Brotli 1.1.0 -68.3880.67758,571,909
Zstd 1.5.6 -13 -T163.2440.27258,041,112
Brotli 1.1.0 -970.070.67756,376,419
Bzip2 1.0.8 -916.946.73454,572,500
Kanzi -l 52.1611.04354,039,773
Zstd 1.5.6 -19 -T1620.870.30352,889,925
Kanzi -l 62.7792.05649,567,817
Lzma 5.4.5 -995.973.17248,745,354
Kanzi -l 73.7382.88847,520,629
bzip3 1.3.2.r4-gb2d61e8 -j 162.6823.22147,237,088
Kanzi -l 819.4720.0143,167,429
Kanzi -l 945.1745.5541,497,835
zpaq 7.15 -m5 -t16213.8213.840,050,429

enwik8

Download at https://mattmahoney.net/dc/enwik8.zip

CompressorEncoding (sec)Decoding (sec)Size
Original100,000,000
Kanzi -l 10.4250.14943,746,017
Kanzi -l 20.4320.17937,816,913
Kanzi -l 30.6830.24533,865,383
Kanzi -l 40.6210.36529,597,577
Kanzi -l 50.8080.43726,528,023
Kanzi -l 61.2120.91624,076,674
Kanzi -l 72.3212.75522,817,373
Kanzi -l 812.5212.2721,181,983
Kanzi -l 932.2432.2720,035,138

Round-trip scores for LZ

Below is a table showing silesia.tar compressed using different LZ compressors (no entropy) in single-threaded mode.

The efficiency score is computed as such: score(lambda) = compTime + 2 x decompTime + 10^-lambda x compSize

A lower score is better. Best scores are in bold.

Tested on Ubuntu 22.04.4 LTS, i7-7700K CPU @ 4.20GHz, 32 GB RAM

CompressorEncoding (sec)Decoding (sec)SizeScore(5)Score(6)Score(7)
Lz40.910.5398375894985.73100.3511.81
s2 -cpu 10.810.4086646819868.0888.2510.27
Kanzi 2.3 -t lz -j 11.300.3383355862835.5285.3110.29
Kanzi 2.3 -t lzx -j 11.580.3081485228817.0483.6710.33

References: S2 LZ4 (go)

Build

Using formal releases is recommended (see https://github.com/flanglet/kanzi-go/releases).

go install github.com/flanglet/kanzi-go/v2/app@v2.3.0

Otherwise, to build manually from the latest tag, follow the instructions below:

git clone https://github.com/flanglet/kanzi-go.git

cd kanzi-go/v2/app

go build Kanzi.go BlockCompressor.go BlockDecompressor.go InfoPrinter.go

Credits

Matt Mahoney, Yann Collet, Jan Ondrus, Yuta Mori, Ilya Muravyov, Neal Burns, Fabian Giesen, Jarek Duda, Ilya Grebnov

Disclaimer

Use at your own risk. Always keep a copy of your original files.