Home

Awesome

Kanzi

Kanzi is a modern, modular, portable and efficient lossless data compressor implemented in C++.

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 C and C++ APIs: here

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

There is Go implementation available here: https://github.com/flanglet/kanzi-go

Build Status Quality Gate Status Lines of Code <a href="https://scan.coverity.com/projects/flanglet-kanzi-cpp"> <img alt="Coverity Scan Build Status" src="https://img.shields.io/coverity/scan/16859.svg"/> </a> 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

Test machine:

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

Ubuntu clang++ version 15.0.7 + tcmalloc

Ubuntu 24.04 LTS

Kanzi version 2.3.0 C++ implementation

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
Kanzi -l 10.2630.23180,277,212
Lz4 1.9.5 -40.3210.33079,912,419
Zstd 1.5.6 -2 -T160.1510.27169,556,157
Kanzi -l 20.2670.25368,195,845
Brotli 1.1.0 -21.7490.76168,041,629
Gzip 1.12 -920.091.40367,652,449
Kanzi -l 30.4460.28765,613,695
Zstd 1.5.6 -5 -T160.3560.28963,131,656
Kanzi -l 40.5430.37361,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.76156,376,419
Bzip2 1.0.8 -916.946.73454,572,500
Kanzi -l 51.6270.88354,039,773
Zstd 1.5.6 -19 -T1620.870.30352,889,925
Kanzi -l 62.3121.22749,567,817
Lzma 5.4.5 -995.973.17248,745,354
Kanzi -l 72.6862.55347,520,629
bzip3 1.3.2.r4-gb2d61e8 -j 162.6823.22147,237,088
Kanzi -l 87.2608.02143,167,429
Kanzi -l 918.9921.0741,497,835
zpaq 7.15 -m5 -t16213.8213.840,050,429

enwik8

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

Tested on Ubuntu 22.04.4 LTS, i7-7700K CPU @ 4.20GHz, 32 GB RAM, clang-15, 4 threads (default)

CompressorEncoding (ms)Decoding (ms)Size
Original100,000,000
Kanzi -l 12518743,746,017
Kanzi -l 226811437,816,913
Kanzi -l 351217533,865,383
Kanzi -l 454624929,597,577
Kanzi -l 5103050026,528,023
Kanzi -l 6153779924,076,674
Kanzi -l 72695204522,817,373
Kanzi -l 87217731421,181,983
Kanzi -l 9113361157420,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, clang-15

CompressorEncoding (sec)Decoding (sec)SizeScore(5)Score(6)Score(7)
FastLZ -21.850.841011141531014.66104.6313.63
Lizard 1.1.0 -110.760.2493967850940.9195.2010.63
Lz4 1.9.5 -2 -T10.810.2189208908893.3290.4410.15
Lzturbo 1.2 -11 -p01.090.3488657053888.3590.4310.64
lzav (1)0.520.1988221200883.1289.139.73
s2 -cpu 10.810.4086646819868.0888.2510.27
LZ4x 1.60 -21.130.2287883674880.4089.4410.35
lzav (2)0.670.4086505609866.5387.9810.12
Lizard 1.1.0 -121.480.2386340434865.3588.2910.58
LZ4x 1.60 -31.360.2485483806856.6787.3210.38
Kanzi 2.3 -t lz -j 1 (1)0.830.2483355862834.8784.679.65
Lzturbo 1.2 -12 -p02.400.2283179291834.6386.0211.16
Kanzi 2.3 -t lz -j 1 (2)0.990.3582652955828.2284.349.96
Kanzi 2.3 -t lzx -j 1 (1)1.090.2281485228816.3983.029.68
Lz4 1.9.5 -3 -T12.330.2181441623817.1784.1910.90
Kanzi 2.3 -t lzx -j 1 (2)1.520.3579014650792.3781.2310.12

References:

FastLZ Lizard LZ4 S2 LZAV LZ4x LZTurbo

lz4@97291fc50

kanzi@af12d07f2

lzav@10f7e2ac

(1) processing 4MB blocks

(2) processing whole file at once

More benchmarks

Comprehensive lzbench benchmarks

More round trip scores

Build Kanzi

The C++ code can be built on Windows with Visual Studio, Linux, macOS and Android with g++ and/or clang++. There are no dependencies. Porting to other operating systems should be straightforward.

Visual Studio 2008

Unzip the file "Kanzi_VS2008.zip" in place. The solution generates a Windows 32 binary. Multithreading is not supported with this version.

Visual Studio 2022

Unzip the file "Kanzi_VS2022.zip" in place. The solution generates a Windows 64 binary and library. Multithreading is supported with this version.

mingw-w64

Go to the source directory and run 'make clean && mingw32-make.exe kanzi'. The Makefile contains all the necessary targets. Tested successfully on Win64 with mingw-w64 g++ 8.1.0. Multithreading is supportedwith g++ version 5.0.0 or newer. Builds successfully with C++11, C++14, C++17.

Linux

Go to the source directory and run 'make clean && make kanzi'. The Makefile contains all the necessary targets. Build successfully on Ubuntu with many versions of g++ and clang++. Multithreading is supported with g++ version 5.0.0 or newer. Builds successfully with C++98, C++11, C++14, C++17, C++20.

MacOS

Go to the source directory and run 'make clean && make kanzi'. The Makefile contains all the necessary targets. Build successfully on MacOs with several versions of clang++. Multithreading is supported.

BSD

The makefile uses the gnu-make syntax. First, make sure gmake is present (or install it: 'pkg_add gmake'). Go to the source directory and run 'gmake clean && gmake kanzi'. The Makefile contains all the necessary targets. Multithreading is supported.

Makefile targets

clean:     removes objects, libraries and binaries
kanzi:     builds the kanzi executable
lib:       builds static and dynamic libraries
test:      builds test binaries
all:       kanzi + lib + test
install:   installs libraries, headers and executable
uninstall: removes installed libraries, headers and executable

For those who prefer cmake, run the following commands:

mkdir build
cd build
cmake ..
make

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.