Closed Akash-Panigrahi closed 1 year ago
It looks like you initialize wasm-vips on every createMultiPageImage()
call. I would initialize wasm-vips only once and reuse its instance. For example:
With that, I see:
flop
{
"rss": 123,
"heapTotal": 31,
"heapUsed": 13,
"external": 7,
"arrayBuffers": 5
}
negate
{
"rss": 125,
"heapTotal": 31,
"heapUsed": 13,
"external": 7,
"arrayBuffers": 5
}
flip
{
"rss": 242,
"heapTotal": 31,
"heapUsed": 14,
"external": 9,
"arrayBuffers": 7
}
rotate
{
"rss": 263,
"heapTotal": 31,
"heapUsed": 14,
"external": 14,
"arrayBuffers": 11
}
trim
{
"rss": 275,
"heapTotal": 31,
"heapUsed": 14,
"external": 19,
"arrayBuffers": 16
}
Which is probably reasonable for image processing in WebAssembly.
This definitely looks promising. Currently busy with work, but will definitely check this out and revert back. Thank you for checking the issue. 🙏🏾
Just implemented the above logic and working flawlessly. Apart from the initial memory jump, all other subsequent vips calls are within constraint. Thank you @kleisauke for the fix and also for the amazing package. 🙇🏾♂️
I am trying to perform certain operations on a multi-page tiff image using the sharp package. Except for
trim
,flip
androtate
, all needed operations are successfully performed by sharp.For
flip
, sharp flips the whole image and its order too. Fortrim
androtate
, it simply throws an error. This is a known issue, https://github.com/lovell/sharp/issues/1580.Using the
vips.Image.arrayjoin
function, I was able to get the desired output, but overtime it increases myrss
memory size drastically, eventually killing the process. The heap is not increasing as theGC
works promptly. The memory jump happens at thewriteToBuffer
function call.Is there any different way of getting the same results, without the
rss
size jump?Attaching the code and the input image. Thank you.
Code to create the image (handle-multi-image.mjs)
Output
Image file multipage.tiff