zstd

1.5.7

Zstandard - Fast real-time compression algorithm
facebook/zstd

What's New

Zstandard v1.5.7

2025-02-19T21:50:11Z

Zstandard v1.5.7 is a significant release, featuring over 500 commits accumulated over the past year. This update brings enhancements across various domains, including performance, stability, and functionality, and is particularly recommended for 32-bit users due to a bug fix detailed below.

edit: man pages were not properly updated in this package, and are still pointing to v1.5.6. If you want the v1.5.7 version, they are updated in dev branch, and can be cherry-picked using commit 6af3842. Alternatively, they can also be built locally using make manual and make -C programs man.

Performance Enhancements

Enhanced Compression Speed for Small Data Blocks

The compression speed for small data blocks has been notably improved at fast compression levels, thanks to contributions from @TocarIP, further extended in #4165. Below are benchmark results illustrating the performance improvements for level 1 compression on the Silesia corpus, segmented into different block sizes:

Block Size v1.5.6 v1.5.7 Improv.
4 KB 280 MB/s 310 MB/s +10%
8 KB 328 MB/s 364 MB/s +11%
16 KB 360 MB/s 396 MB/s +10%
32 KB 383 MB/s 458 MB/s +20%
64 KB 423 MB/s 474 MB/s +12%
128 KB 460 MB/s 485 MB/s +5%

These improvements are particularly beneficial in data centers and databases, where data is often divided into small segments to enhance seekability. A notable example is RocksDB, which is frequently configured with block sizes around 16 KB. Such systems will experience an immediate performance boost by updating their compression library to v1.5.7.

Additionally, the speed improvements partially extend to dictionary compression, with observed gains ranging from none to +15%.

Substantial --patch-from improvements

The --patch-from functionality of the zstd CLI allows for differential compression of a file given an older version, similar to bsdiff. While compression levels impact processing speed and compression ratio as expected, at high compression levels (18+), speed was previously reduced to uncomfortable levels.

v1.5.7 largely mitigates the speed impact of high compression levels 18+, as illustrated in the following scenario, which compresses linux-6.13.tar as a difference from linux-6.12.tar using 6 threads:

level v1.5.6 v1.5.7 Improv.
18 210 s 42.7 s x4.9
19 273 s 61.8 s x4.4
20 310 s 82.3 s x3.8
21 365 s 120 s x3.1

Additionally, compression ratio of --patch-from is also substantially improved across the board, including higher compression levels:

level v1.5.6 v1.5.7 Improv.
15 6,383,341 6,003,514 6.3%
16 5,909,932 5,421,444 9.0%
17 5,613,879 5,214,734 7.7%
18 5,584,219 5,075,507 10.0%
19 5,322,658 4,724,116 12.6%
20 5,097,236 4,583,435 11.2%
21 4,648,583 4,297,672 8.1%
22 4,560,051 4,225,283 7.9%
--max N/A 3,999,476

Compression ratio improvements for large files

The compression ratio has been enhanced slightly for large data across all compression levels, thanks to a refined approach in selecting block boundaries. This improvement is more pronounced at lower compression levels (≤ 15), where the previous boundary selection method was relatively basic. In contrast, higher compression levels (16+) already employed some analysis, but still benefit from the introduction of the new heuristic, resulting in marginally better compression ratios.

A comparison of the compression ratios between v1.5.6 and v1.5.7 is presented below:

level v1.5.6 v1.5.7 Improv.
1 73,492,125 73,292,801 -199,324
3 66,555,241 66,217,754 -337,487
6 61,614,472 61,350,571 -263,901
8 60,089,890 59,816,878 -273,012
12 58,297,345 58,039,924 -257,421
15 57,290,517 57,031,235 -259,282
16 55,341,618 55,304,857 -36,761
19 52,876,557 52,840,800 -35,757
22 52,326,420 52,289,718 -36,702

Command-Line Interface Updates

Recognizing the prevalence of multi-core systems, zstd now employs multiple threads by default, thanks to #4211 by @daniellerozenblit
In v1.5.7, systems will see default threading scaled according to capability, but remains cautious to mitigate risks of overloading surprises on existing user base, with a maximum of 4 threads by default.
For example, a typical "low-end" system with 4 cores and hyperthreading will employ 2 threads by default. A "higher-end" system with 8 cores and hyperthreading will employ 4 threads by default.

These modifications only impact default settings. As usual, the number of threads that zstd uses can also be set manually, either via command line or via environment variables.

Additionally, a new zstd command --max is available, designed to maximize compression ratios by leveraging all parameters, at the expense of time and memory. It's slower and more resource hungry than --ultra -22, but achieves denser compressed archives if that's the goal. For instance, compressing enwik9 (1,000,000,000 bytes) at --max level on a i7-9700k platform yields:

level cSize cTime cMem
--ultra -22 213,898,083 ~6 mn ~ 3 GB
--max 202,507,076 ~72 mn ~ 18 GB

Bug Fixes

v1.5.7 resolves a long standing and very rare compression issue in 32-bit mode, which can be triggered during long-lasting sessions (same ZSTD_CCtx* being continuously reused). This issue required several conditions to be met and a large amount of data to occur, but at the scale of zstd usage, it has been observed and reported (#4292).
In summary, if you use libzstd in 32-bit mode, this update is highly recommended.

Miscellaneous

The release also brings its lot of various improvements, impacting build scripts (cmake, meson, Apple Framework, Visual Studio), documentation and portability (QNX, FreeBSD, Hurd, icc/icx).
Notably, there are measurable performance gains for binaries produced with Visual Studio, as a cumulative result of several contributions.

Changelog:

  • fix: compression bug in 32-bit mode associated with long-lasting sessions
  • perf: substantial compression speed improvements (up to +30%) on small data, by @TocarIP (#4144) and @Cyan4973 (#4165)
  • perf: improved compression speed (~+5%) for dictionary compression at low levels (#4170)
  • perf: much faster --patch-from at high compression levels (#4276)
  • perf: higher --patch-from compression ratios, notably at high levels (#4288)
  • perf: better speed for binaries on Windows (@pps83) and when compiled with Visual Studio (@MessyHack)
  • perf: slightly improve compression ratio across all levels thanks to better block boundaries (#4136, #4176, #4178)
  • perf: slight compression ratio improvement for dfast, aka levels 3 and 4 (#4171)
  • perf: runtime bmi2 detection now also enabled on x86 32-bit mode (#4251)
  • cli: multi-threading as default CLI setting, by @daniellerozenblit
  • cli: new --max command (#4290)
  • api: new method ZSTD_compressSequencesAndLiterals() (#4217, #4232)
  • api: ZSTD_getFrameHeader() now works on skippable frames (#4228)
  • build: improve msbuild version autodetection, support VS2022, by @ManuelBlanc
  • build: fix meson build by @artem and @Victor-C-Zhang, and on Windows by @bgilbert
  • build: compatibility with Apple Framework, by @Treata11
  • build: improve icc/icx compatibility, by @josepho0918 and @luau-project
  • build: improve compatibility with Android NDK, by Adenilson Cavalcanti
  • portability: linux kernel branch, with improved support for Sequence producers (@embg, @gcabiddu, @Cyan4973)
  • portability: improved qnx compatibility, suggested by @rainbowball
  • portability: improved install script for FreeBSD, by @sunpoet
  • portability: fixed test suite compatibility with gnu hurd, by @diegonc
  • doc: clarify specification, by @elasota
  • misc: improved tests/decodecorpus validation tool (#4102), by antmicro

New Contributors

Full Changelog: v1.5.6...v1.5.7

Zstandard

Zstandard, or zstd as short version, is a fast lossless compression algorithm, targeting real-time compression scenarios at zlib-level and better compression ratios. It's backed by a very fast entropy stage, provided by Huff0 and FSE library.

Zstandard's format is stable and documented in RFC8878. Multiple independent implementations are already available. This repository represents the reference implementation, provided as an open-source dual BSD OR GPLv2 licensed C library, and a command line utility producing and decoding .zst, .gz, .xz and .lz4 files. Should your project require another programming language, a list of known ports and bindings is provided on Zstandard homepage.

Development branch status:

Build Status Build status Build status Fuzzing Status

Benchmarks

For reference, several fast compression algorithms were tested and compared on a desktop featuring a Core i7-9700K CPU @ 4.9GHz and running Ubuntu 20.04 (Linux ubu20 5.15.0-101-generic), using lzbench, an open-source in-memory benchmark by @inikep compiled with gcc 9.4.0, on the Silesia compression corpus.

Compressor name Ratio Compression Decompress.
zstd 1.5.6 -1 2.887 510 MB/s 1580 MB/s
zlib 1.2.11 -1 2.743 95 MB/s 400 MB/s
brotli 1.0.9 -0 2.702 395 MB/s 430 MB/s
zstd 1.5.6 --fast=1 2.437 545 MB/s 1890 MB/s
zstd 1.5.6 --fast=3 2.239 650 MB/s 2000 MB/s
quicklz 1.5.0 -1 2.238 525 MB/s 750 MB/s
lzo1x 2.10 -1 2.106 650 MB/s 825 MB/s
lz4 1.9.4 2.101 700 MB/s 4000 MB/s
lzf 3.6 -1 2.077 420 MB/s 830 MB/s
snappy 1.1.9 2.073 530 MB/s 1660 MB/s

The negative compression levels, specified with --fast=#, offer faster compression and decompression speed at the cost of compression ratio.

Zstd can also offer stronger compression ratios at the cost of compression speed. Speed vs Compression trade-off is configurable by small increments. Decompression speed is preserved and remains roughly the same at all settings, a property shared by most LZ compression algorithms, such as zlib or lzma.

The following tests were run on a server running Linux Debian (Linux version 4.14.0-3-amd64) with a Core i7-6700K CPU @ 4.0GHz, using lzbench, an open-source in-memory benchmark by @inikep compiled with gcc 7.3.0, on the Silesia compression corpus.

Compression Speed vs Ratio Decompression Speed
Compression Speed vs Ratio Decompression Speed

A few other algorithms can produce higher compression ratios at slower speeds, falling outside of the graph. For a larger picture including slow modes, click on this link.

The case for Small Data compression

Previous charts provide results applicable to typical file and stream scenarios (several MB). Small data comes with different perspectives.

The smaller the amount of data to compress, the more difficult it is to compress. This problem is common to all compression algorithms, and reason is, compression algorithms learn from past data how to compress future data. But at the beginning of a new data set, there is no "past" to build upon.

To solve this situation, Zstd offers a training mode, which can be used to tune the algorithm for a selected type of data. Training Zstandard is achieved by providing it with a few samples (one file per sample). The result of this training is stored in a file called "dictionary", which must be loaded before compression and decompression. Using this dictionary, the compression ratio achievable on small data improves dramatically.

The following example uses the github-users sample set, created from github public API. It consists of roughly 10K records weighing about 1KB each.

Compression Ratio Compression Speed Decompression Speed
Compression Ratio Compression Speed Decompression Speed

These compression gains are achieved while simultaneously providing faster compression and decompression speeds.

Training works if there is some correlation in a family of small data samples. The more data-specific a dictionary is, the more efficient it is (there is no universal dictionary). Hence, deploying one dictionary per type of data will provide the greatest benefits. Dictionary gains are mostly effective in the first few KB. Then, the compression algorithm will gradually use previously decoded content to better compress the rest of the file.

Dictionary compression How To:

  1. Create the dictionary

    zstd --train FullPathToTrainingSet/* -o dictionaryName

  2. Compress with dictionary

    zstd -D dictionaryName FILE

  3. Decompress with dictionary

    zstd -D dictionaryName --decompress FILE.zst

Build instructions

make is the officially maintained build system of this project. All other build systems are "compatible" and 3rd-party maintained, they may feature small differences in advanced options. When your system allows it, prefer using make to build zstd and libzstd.

Makefile

If your system is compatible with standard make (or gmake), invoking make in root directory will generate zstd cli in root directory. It will also create libzstd into lib/.

Other available options include:

  • make install : create and install zstd cli, library and man pages
  • make check : create and run zstd, test its behavior on local platform

The Makefile follows the GNU Standard Makefile conventions, allowing staged install, standard flags, directory variables and command variables.

For advanced use cases, specialized compilation flags which control binary generation are documented in lib/README.md for the libzstd library and in programs/README.md for the zstd CLI.

cmake

A cmake project generator is provided within build/cmake. It can generate Makefiles or other build scripts to create zstd binary, and libzstd dynamic and static libraries.

By default, CMAKE_BUILD_TYPE is set to Release.

Support for Fat (Universal2) Output

zstd can be built and installed with support for both Apple Silicon (M1/M2) as well as Intel by using CMake's Universal2 support. To perform a Fat/Universal2 build and install use the following commands:

cmake -B build-cmake-debug -S build/cmake -G Ninja -DCMAKE_OSX_ARCHITECTURES="x86_64;x86_64h;arm64"
cd build-cmake-debug
ninja
sudo ninja install

Meson

A Meson project is provided within build/meson. Follow build instructions in that directory.

You can also take a look at .travis.yml file for an example about how Meson is used to build this project.

Note that default build type is release.

VCPKG

You can build and install zstd vcpkg dependency manager:

git clone https://github.com/Microsoft/vcpkg.git
cd vcpkg
./bootstrap-vcpkg.sh
./vcpkg integrate install
./vcpkg install zstd

The zstd port in vcpkg is kept up to date by Microsoft team members and community contributors. If the version is out of date, please create an issue or pull request on the vcpkg repository.

Conan

You can install pre-built binaries for zstd or build it from source using Conan. Use the following command:

conan install --requires="zstd/[*]" --build=missing

The zstd Conan recipe is kept up to date by Conan maintainers and community contributors. If the version is out of date, please create an issue or pull request on the ConanCenterIndex repository.

Visual Studio (Windows)

Going into build directory, you will find additional possibilities:

  • Projects for Visual Studio 2005, 2008 and 2010.
    • VS2010 project is compatible with VS2012, VS2013, VS2015 and VS2017.
  • Automated build scripts for Visual compiler by @KrzysFR, in build/VS_scripts, which will build zstd cli and libzstd library without any need to open Visual Studio solution.

Buck

You can build the zstd binary via buck by executing: buck build programs:zstd from the root of the repo. The output binary will be in buck-out/gen/programs/.

Bazel

You easily can integrate zstd into your Bazel project by using the module hosted on the Bazel Central Repository.

Testing

You can run quick local smoke tests by running make check. If you can't use make, execute the playTest.sh script from the src/tests directory. Two env variables $ZSTD_BIN and $DATAGEN_BIN are needed for the test script to locate the zstd and datagen binary. For information on CI testing, please refer to TESTING.md.

Status

Zstandard is currently deployed within Facebook and many other large cloud infrastructures. It is run continuously to compress large amounts of data in multiple formats and use cases. Zstandard is considered safe for production environments.

License

Zstandard is dual-licensed under BSD OR GPLv2.

Contributing

The dev branch is the one where all contributions are merged before reaching release. If you plan to propose a patch, please commit into the dev branch, or its own feature branch. Direct commit to release are not permitted. For more information, please read CONTRIBUTING.

Description

  • Swift Tools 5.0.0
View More Packages from this Author

Dependencies

  • None
Last updated: Fri May 16 2025 01:08:56 GMT-0900 (Hawaii-Aleutian Daylight Time)