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

Investigate SIMD-accelerated zlib implementations #25

Closed
kleisauke opened this issue Jul 31, 2019 · 3 comments · Fixed by #96
Closed

Investigate SIMD-accelerated zlib implementations #25

kleisauke opened this issue Jul 31, 2019 · 3 comments · Fixed by #96

Comments

@kleisauke
Copy link
Collaborator

It might be worth switching to a performance-oriented fork of the popular zlib library within the prebuild libvips binaries. Several companies have made zlib significantly faster by using modern CPU instructions (SSE, ARM NEON).

The zlib-ng project seems the most promising, it has merged the changes of both Cloudflare and Intel forks and cleans up the code in general. It's API / ABI compatible with zlib (when configured with --zlib-compat or -DZLIB_COMPAT=ON), so it can be used as a drop-in replacement (just like libjpeg-turbo).

There is no "stable" release for zlib-ng yet, so it might be too risky to migrate now. However, it's already been continuously fuzzed by OSS-Fuzz[1] and the Chromium / AOSP developers are also interested in switching to this fork[2][3].

I've already done some experiments with zlib-ng within the MXE-based Windows builds[4], and see a nice performance improvement by converting a 4,000 x 5,000 JPEG image to PNG with different compression values[5].

[1] https://github.com/google/oss-fuzz/tree/master/projects/zlib-ng
[2] https://crbug.com/687631
[3] https://groups.google.com/a/chromium.org/d/msg/blink-dev/T3rPfd6G6ps/l8pAk7gnBgAJ
[4] https://github.com/libvips/build-win64-mxe/tree/zlib-ng-experiment
[5] https://gist.github.com/kleisauke/879e3075a675c6f945dff3772d2ef0a3

@lovell
Copy link
Owner

lovell commented Jul 31, 2019

Thanks, I think we'd want to wait for a stable/supported release before making the switch.

I recall some of the Cloudflare changes were GPL-licenced but it doesn't look like these made it across.

@lovell
Copy link
Owner

lovell commented Jan 19, 2021

There's a release candidate of zlib-ng at https://github.com/zlib-ng/zlib-ng/releases/tag/v2.0.0-RC1

@lovell
Copy link
Owner

lovell commented Feb 28, 2021

I've created a WIP branch that switches to the latest zlib-ng release candidate (RC2).

https://github.com/lovell/sharp-libvips/actions/runs/607358257

The sharp tests pass locally on Linux x64 using the resultant binary too.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants