next-optimized-images icon indicating copy to clipboard operation
next-optimized-images copied to clipboard

[canary] wasm - could not allocate memory

Open andreisergiu98 opened this issue 5 years ago • 2 comments
trafficstars

Hi! I have a lot of images, and i build a lot of variants for each image. And when i use the optimize: true option it takes a lot of time to optimize them and in the end it fails

RuntimeError: abort(RangeError: WebAssembly.Memory(): could not allocate memory). Build with -s ASSERTIONS=1 for more info.
    at process.abort (/home/andrei/Projects/Web/node_modules/@wasm-codecs/mozjpeg/lib/mozjpeg.js:9:11556)
    at process.emit (events.js:327:22)
    at processEmit [as emit] (/home/andrei/Projects/Web/node_modules/next/dist/compiled/ora/index.js:1:2260)
    at processPromiseRejections (internal/process/promises.js:209:33)
    at processTicksAndRejections (internal/process/task_queues.js:98:32)
error Command failed with exit code 7.

I think there is a limit to how much memory it can use. My node version is 12.18.3

andreisergiu98 avatar Aug 20 '20 10:08 andreisergiu98

I tried to build @wasm/mozjpeg with MAXIMUM_MEMORY=4GB and it still throws the error and it's the maximum we can get. I think the problem is webpack processing all image imports in parallel, that with some cpu interrupts and it's populating the ram like crazy without it being capable to free the memory because the images are still being processed. I think we could fix the problem by processing a maximum of cpu threads + 1 number of images in parallel. This could be achieved with some kind of internal state in the loader where we keep track of the number of images currently processed, but i don't know if it's possible with webpack, i'll make some research.

andreisergiu98 avatar Aug 25 '20 11:08 andreisergiu98

Can we get an official fix for this? happens to me as well

Nadav42 avatar Oct 06 '20 15:10 Nadav42