Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use zstd compression in NRRD and MetaIO #348

Closed
dzenanz opened this issue Dec 22, 2018 · 9 comments
Closed

Use zstd compression in NRRD and MetaIO #348

dzenanz opened this issue Dec 22, 2018 · 9 comments
Assignees
Labels
area:IO Issues affecting the IO module area:ThirdParty Issues affecting the ThirdParty module status:Backlog Postponed without a fixed deadline type:Infrastructure Infrastructure/ecosystem related changes, such as CMake or buildbots type:Performance Improvement in terms of compilation or execution time

Comments

@dzenanz
Copy link
Member

dzenanz commented Dec 22, 2018

[Background discussion]

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.

@dzenanz dzenanz added type:Infrastructure Infrastructure/ecosystem related changes, such as CMake or buildbots type:Performance Improvement in terms of compilation or execution time area:IO Issues affecting the IO module area:ThirdParty Issues affecting the ThirdParty module labels Dec 22, 2018
@dzenanz dzenanz added this to the ITK v5.0rc01 milestone Dec 22, 2018
@neurolabusc
Copy link

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.

@hjmjohnson
Copy link
Member

@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.

@stale
Copy link

stale bot commented Aug 11, 2019

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.

@stale stale bot added the status:Backlog Postponed without a fixed deadline label Aug 11, 2019
@jamesobutler
Copy link
Contributor

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

@stale stale bot removed the status:Backlog Postponed without a fixed deadline label Aug 31, 2019
@neurolabusc
Copy link

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.

@dzenanz
Copy link
Member Author

dzenanz commented Jan 8, 2020

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

@gdevenyi
Copy link
Contributor

gdevenyi commented Jan 8, 2020

Also #416

@stale
Copy link

stale bot commented May 7, 2020

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

@stale stale bot added the status:Backlog Postponed without a fixed deadline label May 7, 2020
@dzenanz
Copy link
Member Author

dzenanz commented Nov 15, 2021

I am giving up on this as zlib-ng was integrated via #2708 and #2803, adding zstd to NRRD and MetaIO is major undertaking, and there is ongoing OME-Zarr effort.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area:IO Issues affecting the IO module area:ThirdParty Issues affecting the ThirdParty module status:Backlog Postponed without a fixed deadline type:Infrastructure Infrastructure/ecosystem related changes, such as CMake or buildbots type:Performance Improvement in terms of compilation or execution time
Projects
None yet
Development

No branches or pull requests

6 participants