Skip to content

NF: Add zstd compression support #1005

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

Merged
merged 11 commits into from
Jun 5, 2021
Merged

Conversation

vanandrew
Copy link
Contributor

Some stuff I was playing around with... This PR adds zstd compression/decompression support for the Opener class.

zstd (Zstandard) is a relatively new compression library that boasts significant improvements in compression/decompression speeds over zlib with minimal differences in compression ratios.

Results from bench_fileslice.py with zst added:

*************************
Bytes slice - raw (ratio)
*************************

+-----------------+--------------+--------------+--------------+--------------+
|                 |   mid int    |    step 1    | half step 1  | step mid int |
+=================+==============+==============+==============+==============+
| axis 0, len 64  | 0.73 (4.40)  | 0.23 (1.38)  | 0.21 (1.25)  | 0.19 (1.15)  |
| axis 1, len 64  | 0.02 (0.12)  | 0.17 (1.01)  | 0.13 (0.81)  | 0.02 (0.14)  |
| axis 2, len 32  | 0.01 (0.04)  | 0.12 (0.73)  | 0.13 (0.77)  | 0.02 (0.14)  |
| axis 3, len 100 | 0.00 (0.00)  | 0.15 (0.90)  | 0.09 (0.56)  | 0.00 (0.03)  |
+-----------------+--------------+--------------+--------------+--------------+
Base time: 0.17

************************
File slice - raw (ratio)
************************

+-----------------+--------------+--------------+--------------+--------------+
|                 |   mid int    |    step 1    | half step 1  | step mid int |
+=================+==============+==============+==============+==============+
| axis 0, len 64  | 1.19 (10.13) | 0.16 (1.40)  | 0.16 (1.36)  | 0.11 (0.96)  |
| axis 1, len 64  | 0.03 (0.24)  | 0.12 (1.04)  | 0.17 (1.44)  | 0.07 (0.59)  |
| axis 2, len 32  | 0.01 (0.07)  | 0.17 (1.42)  | 0.15 (1.28)  | 0.02 (0.15)  |
| axis 3, len 100 | 0.00 (0.01)  | 0.15 (1.31)  | 0.07 (0.60)  | 0.01 (0.04)  |
+-----------------+--------------+--------------+--------------+--------------+
Base time: 0.12

**********************
gz slice - raw (ratio)
**********************

+-----------------+--------------+--------------+--------------+--------------+
|                 |   mid int    |    step 1    | half step 1  | step mid int |
+=================+==============+==============+==============+==============+
| axis 0, len 64  | 3.21 (2.41)  | 1.32 (0.99)  | 1.15 (0.86)  | 1.15 (0.86)  |
| axis 1, len 64  | 1.23 (0.92)  | 1.19 (0.89)  | 1.29 (0.96)  | 1.64 (1.23)  |
| axis 2, len 32  | 1.36 (1.02)  | 1.19 (0.89)  | 1.27 (0.95)  | 1.31 (0.98)  |
| axis 3, len 100 | 0.58 (0.43)  | 1.21 (0.91)  | 0.58 (0.43)  | 0.60 (0.45)  |
+-----------------+--------------+--------------+--------------+--------------+
Base time: 1.34

***********************
zst slice - raw (ratio)
***********************

+-----------------+--------------+--------------+--------------+--------------+
|                 |   mid int    |    step 1    | half step 1  | step mid int |
+=================+==============+==============+==============+==============+
| axis 0, len 64  | 2.09 (4.08)  | 0.65 (1.27)  | 0.51 (0.99)  | 0.48 (0.94)  |
| axis 1, len 64  | 0.80 (1.56)  | 0.50 (0.98)  | 0.57 (1.11)  | 0.46 (0.91)  |
| axis 2, len 32  | 0.36 (0.71)  | 0.52 (1.01)  | 0.45 (0.89)  | 0.37 (0.72)  |
| axis 3, len 100 | 0.17 (0.34)  | 0.46 (0.89)  | 0.19 (0.37)  | 0.18 (0.36)  |
+-----------------+--------------+--------------+--------------+--------------+
Base time: 0.51

- Add zstandard compression for analyze format images via pyzstd.
- Add zstd option under setup.cfg options.extra_requires.
@pep8speaks
Copy link

pep8speaks commented Mar 23, 2021

Hello @vanandrew, Thank you for updating!

Cheers! There are no style issues detected in this Pull Request. 🍻 To test for issues locally, pip install flake8 and then run flake8 nibabel.

Comment last updated at 2021-06-04 17:54:08 UTC

@codecov
Copy link

codecov bot commented Mar 23, 2021

Codecov Report

Merging #1005 (258d0cd) into master (62aea04) will decrease coverage by 0.00%.
The diff coverage is 100.00%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #1005      +/-   ##
==========================================
- Coverage   92.26%   92.26%   -0.01%     
==========================================
  Files         100      100              
  Lines       12164    12201      +37     
  Branches     2128     2134       +6     
==========================================
+ Hits        11223    11257      +34     
- Misses        615      616       +1     
- Partials      326      328       +2     
Impacted Files Coverage Δ
nibabel/analyze.py 98.52% <100.00%> (ø)
nibabel/brikhead.py 97.50% <100.00%> (ø)
nibabel/loadsave.py 93.84% <100.00%> (+1.25%) ⬆️
nibabel/minc1.py 90.24% <100.00%> (ø)
nibabel/openers.py 95.57% <100.00%> (+0.47%) ⬆️
nibabel/volumeutils.py 93.52% <100.00%> (-0.38%) ⬇️
nibabel/nifti1.py 92.10% <0.00%> (-0.46%) ⬇️
nibabel/filebasedimages.py 88.65% <0.00%> (+1.41%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 62aea04...258d0cd. Read the comment docs.

- Fix code formatting issues
- Remove unused imports
- Fix undefined reference to ZstdFile when pyzstd missing
@effigies
Copy link
Member

Thanks for this! Been a little burnt out, so trying to take it easy this week. If nobody does a proper review by next Monday, please feel free to @ me.

@effigies
Copy link
Member

@vanandrew Thanks for your patience. Overall this looks good, and I wanted to try my suggestions before sending you down the rabbit hole, so I ended up just submitting vanandrew#1.

@vanandrew
Copy link
Contributor Author

vanandrew commented Jun 1, 2021

Almost forgot about this PR myself,,, Going on vacation starting next week, so I'll try to take a look at/merge vanandrew#1 this week before I leave.

RF: Use optional_package to allow code to assume pyzstd is present
@vanandrew
Copy link
Contributor Author

vanandrew commented Jun 4, 2021

Your changes seem fine to me. I merged in vanandrew#1.

@effigies
Copy link
Member

effigies commented Jun 5, 2021

Looks good. Thanks for the PR!

@effigies effigies merged commit dd3fae3 into nipy:master Jun 5, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants