-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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
Converting to AVIF takes 100% of all cores, and 2.5GB+ RAM #2597
Comments
Yes, this is expected as AVIF compression is relatively slow and memory hungry compared with most other formats. Using the following code sample and your test image: await sharp("109366574-9f44d980-7848-11eb-82f5-fffa19163db1.jpg")
.avif({ speed: 8 })
.toFile("out.avif") ...when run locally on Linux (x64 CPU with AVX2) via callgrind using locally compiled and installed libaom, libheif and libvips with symbols intact, I see the top 10 "hottest" functions are:
These are all from within libaom or invoked by it. By setting The prebuilt binaries provided by sharp use libaom as it is the reference de/encoder with good cross-platform support. There is a plan to replace it with the slightly faster dav1d (decode) and rav1e (encode) combination, but I'm unsure of their relative memory consumption. |
It seems any speed setting drives my CPU up to 400% and RAM to 2+GB. I think we'll probably ditch AVIF support in our app until that space matures a little more. Thanks for the detailed reply! |
No worries, please subscribe to #2604 for updates about the migration to dav1d+rav1e. |
As it can make the build process slow and require a lot of memory, see lovell/sharp#2597
Sharing some of the results we tested with different parameters for converting images to AVIF then store in S3 by Lambda function. We ran 10 times and secSpent is the average seconds spent. Just in case people that do not know, more memory Lambda have, more CPU credits we can spend in the lambda function. The source image is 300KB with mainly gradient background with text on it, simply a banner. Setting effort to 0 and 1 are both fast, 2 is very slow already and 3+ are like 1 extra second per effort marginally added. From 1 to 2 it further reduce the size by 25% which is amazing, from 1 to 9 the size would be reduced by 45% down from 20KB to 11KB. If effort 9 would run fast, this would be amazing as our company is paying huge price on CDN.
However, if it is a photographic image, raising effort the file size result in more or less the same.
|
Are you using the latest version? Is the version currently in use as reported by
npm ls sharp
the same as the latest version as reported bynpm view sharp dist-tags.latest
?Yes - 0.27.2
What are the steps to reproduce?
Converting a 4000px wide jpg to avif causes cpu to spike to 400% and takes 2.5gb of RAM vs a webp conversion taking 20% CPU and 200mb of RAM.
What is the expected behaviour?
Conversion to take up less RAM and CPU
Are you able to provide a minimal, standalone code sample, without other dependencies, that demonstrates this problem?
Are you able to provide a sample image that helps explain the problem?
What is the output of running
npx envinfo --binaries --system
?macOS:
Debian:
The text was updated successfully, but these errors were encountered: