-
-
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
Question: .clone() performance issues function of sharp input type. How to fix it ? #2101
Comments
Did you see https://sharp.pixelplumbing.com/performance ? For the same contents, Buffer-based input is generally slightly faster than filesystem-based input. If you're still having problems, please can you provide complete, standalone code sample and image(s) that will allow someone else to reproduce. |
@lovell you can test it here with this repo in 1 minute: I have performances issues when the input is a Buffer, it's much faster with a file path string. The main problem is, in my environment i am forced to use a Buffer input for sharp, but i'm facing this performance issue. What could be the best way to fix it ? Thanks a lot for your help ! |
Thank you. How are you isolating the performance of sharp vs the performance of other parts of this code? For example the use of |
@lovell I guess, once the Buffer is created, it's in the RAM no ? So fs.readFile() is never called again and shouldn't impact sharp treatments. My file image size is only 3Mb. I'll send a simpler example in the next minutes. |
@lovell here we go, you can find a much simpler example here, with the problem isolated: After hours of investigation, it seems that the .clone() method has performance issues when:
WHAT THE TESTS IN MY CODE SHOWFirst, my tests compare 2 different inputs: a small png (32Kb) and "big" png (3Mo). The speed difference is not significant between string path and Buffer input when
The speed difference is SIGNIFICANT between string path and Buffer input when
Do you see a way to fix this performance difference using Buffers as sharp input ?Thanks a lot for your help ! |
It looks like the "fast" tests are benefiting from libvips' cache. You can disable it by adding a For one-input-to-many-outputs scenarios such as this, filesystem-based input is usually a better approach as it allows libvips to manage what is in memory rather than having to have everything in memory. |
Thanks a lot @lovell, so no way in this case to increase performances with Buffer input ? |
As I said in answer to your previous question of a similar nature at #2074 (comment) , the cost here is in the repeated decoding of the PNG input. Were you able to try my suggestion of holding a copy of the input image as raw pixel data in memory? const { data, info } = await sharp(input)
.raw()
.toBuffer({ resolveWithObject: true });
const tile = await sharp(data, { raw: info })
.extract({ ... })
.png()
.toBuffer(); |
Wonderfull @lovell, thought it was working in my previous issue because i used I was missing the Right now performances are higher than |
EDIT: after further investigations bellow, tests revealed it's a .clone() performance issue
What is the best input file format to have the best sharp performance ?
In the code bellow, sharp in 20 times slower in case 1 compared to case 2, why ?
What is the ideal input format ? Base64 ? Blob ?
CASE 1 - SLOW
CASE 2 - FAST
Thanks a lot for your help !
The text was updated successfully, but these errors were encountered: