-
-
Notifications
You must be signed in to change notification settings - Fork 12
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
feat(image): provide fast resize method #34
Conversation
The latest updates on your projects. Learn more about Vercel for Git ↗︎
|
Hi, that doesn't look right, thanks for alerting me to this. The use of sequential read (rather than random access read) might help with such a large image, which you can try via: - await sharp(NASA)
+ await sharp(NASA, { sequentialRead: true }) (I've been considering making this the default behaviour.) If this doesn't help, I should have some time tomorrow to able to check/profile this image and see what's consuming all the CPU time. PNG encoding (rather than anything to do with resizing) would be my best guess right now. As an aside, we're considering the use of the Highway library for SIMD in libvips (and therefore sharp), which should improve resize speed on e.g. AVX2 CPUs. |
With
|
f9b561c
to
b6578d9
Compare
b6578d9
to
f9b561c
Compare
f9b561c
to
9a0d792
Compare
This can reduce memory usage and might improve performance on some systems. Related: Brooooooklyn/Image#34 (comment)
I took a look at the "avif" and "webp" benchmarks in this repo that take a JPEG input, auto-orient, resize, then encode as either WebP or AVIF. Both this library and sharp depend on libwebp and libaom for encoding so I'd expect the results to be closer than those published in the readme. For the JPEG-to-WebP test, which uses with-exif.jpg as the input, calling
and with sharp I see:
So most of the CPU time is spent transforming linear RGB input pixel values to non-linear sRGB using the embedded ICC colour profile.
Manually removing the colour profile shows the calls to lcms2 are gone:
Does |
I also meant to add, as a result of these tests, I found a possible performance regression in sharp when resizing RGBA images, where pixel values were being cast from integer to float, which then meant a slower float-based shrink path was taken. This is fixed via lovell/sharp@9e2207f and will be in sharp v0.32.0 so thank you for bringing it to my attention! It's great to see what you're doing here bringing the world of Rust to Node.js 👍 |
@lovell I found this discussion because I was looking through the history of Next.js and found this related PR: In the latest version of sharp (0.33.3), is it still recommended to set |
@styfle There's no need to set If sharp discovers use of an operation that does not support sequential read, it will insert a cache into the pipeline to store decoded pixel values and allow sequential read of the input to continue. Decoding the input once and once only is generally faster, but at the potential cost of slightly increased memory usage for some operations (e.g. rotation, horizontal flip, Gaussian blur). https://github.com/search?q=repo%3Alovell%2Fsharp%20StaySequential&type=code |
Thanks!
This is the typical workload for Next.js because it has a filesystem cache for optimized images, thus an image is only ever optimized once. However, that same input image could be resized to different widths but those would be different requests so not sure if the sharp cache would be relevant here. |
x86_64 (AVX2)
ARM64 (NEON)