Itk: Use zstd compression in NRRD and MetaIO

Created on 22 Dec 2018  路  8Comments  路  Source: InsightSoftwareConsortium/ITK

[[Background discussion](https://discourse.itk.org/t/add-a-parallel-compression-method-to-nrrd-and-or-metaimage/696)]

zstd's advanced API which supports multithreading has recently entered staging area with intention to be moved into stable API. Now is a great time to make use of it, before ITKv5.0 is released.

IO ThirdParty Backlog Infrastructure Performance

Most helpful comment

This seems related to this discussion. It does seem like the NRRD format needs to be updated to specifically include this.
I do have a couple comments

  1. One option for faster compression in a manner that is fully compatible with existing NRRD data is to use PIGZ for your compression. The recent releases of pigz allow named pipes that allow direct compression, without having to save the uncompressed data to disk first. This offers much faster compression on parallel computers using an existing format. Because it uses the GZ deflate, it is not as fast to compress or decompress as zstd, but it works with all existing tools.
  2. Since this will break compatibility with previous NRRD tools, I would carefully evaluate whether zstd is the ideal choice for your application. zstd is an exceptional generate purpose compression method that is very fast to compress and decompress. However, in my experience its primary weakness is precisely with the data we store in NRRD files: long streams of 16-bit or 32-bit values with strong correlation of the most significant bits across values. In my experience, combining a simple byte-shuffling pre-filter (e.g. blosc) dramatically improves the performance (both in terms of size and speed) of zstd. The zstd developers are aware of this, and I think their next tools will fill this niche. My sense is that such a future tool (or blosc) would be better suited for NRRD than a pure zstd compression.

All 8 comments

This seems related to this discussion. It does seem like the NRRD format needs to be updated to specifically include this.
I do have a couple comments

  1. One option for faster compression in a manner that is fully compatible with existing NRRD data is to use PIGZ for your compression. The recent releases of pigz allow named pipes that allow direct compression, without having to save the uncompressed data to disk first. This offers much faster compression on parallel computers using an existing format. Because it uses the GZ deflate, it is not as fast to compress or decompress as zstd, but it works with all existing tools.
  2. Since this will break compatibility with previous NRRD tools, I would carefully evaluate whether zstd is the ideal choice for your application. zstd is an exceptional generate purpose compression method that is very fast to compress and decompress. However, in my experience its primary weakness is precisely with the data we store in NRRD files: long streams of 16-bit or 32-bit values with strong correlation of the most significant bits across values. In my experience, combining a simple byte-shuffling pre-filter (e.g. blosc) dramatically improves the performance (both in terms of size and speed) of zstd. The zstd developers are aware of this, and I think their next tools will fill this niche. My sense is that such a future tool (or blosc) would be better suited for NRRD than a pure zstd compression.

@dzenanz FYI: I have been assisting zstd with updating their CMake implementation. The community has been fairly receptive to changes that increase it's use.

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

Just adding updated information:

zstd v1.4.0 was released April 16th, 2019.
https://github.com/facebook/zstd/releases/tag/v1.4.0

Advanced API

The main focus of the v1.4.0 release is the stabilization of the advanced API.

Current release is now v1.4.3
https://github.com/facebook/zstd/releases/tag/v1.4.3

Two recent experiments I did may be relevant to this thread. These both focus on making Gzip compression faster, which would retain compatibility with the current NRRD format. One could use this acceleration to use a better compression level, getting a little closer to zstd.

1.) Since pigz is based on zlib, it can be recompiled with the accelerated CloudFlare zlib. Here is a simple CMake script that builds pigz with the CloudFlare zlib:

git clone https://github.com/neurolabusc/pigz.git
cd pigz
mkdir build && cd build

2.) ITK uses znzlib to read/write NIfTI images. My accelerated znzlib demonstrates two methods to accelerate writing gzip images. First, the NIfTI IO can be built using the CloudFlare zlib which is faster than the system zlib. Second, the user can provide an environment variable to request that data is piped to pigz. Only a few lines of code are modified, yielding a dramatic performance increase. I do think the same strategy could be used for the NRRD writing. As my project demonstrates, file writing for uncompressed data and piped pigz are the same, so one can generally use the same existing well tested routines.

The low hanging fruit is zlib-ng, as pointed out in a VTK forum discussion.

Also #416

This issue has been automatically marked as stale because it has not had recent activity. Thank you for your contributions.

Was this page helpful?
0 / 5 - 0 ratings