[LIB/CLI] Butteraugli uses too much memory
See original GitHub issueFirst of all, thanks for making this awesome tool!
Describe the bug
When using “auto” to minify a sufficiently complex image, the butteraugli encode step will use more memory than is available, and will fail with a memory acces out of bounds
error.
It also won’t properly exit the process, as described in #983.
This can be reproduced with any image, but it seems like it has to not only be a large pixel size, but also be visually complex. An image with a flat, simple motive doesn’t seem to be a problem.
To Reproduce
- Use a computer with at most 16GB of RAM (mine has 16GB, not sure if having more will invalidate this example).
- Download the original 3872x2592 “photo.jpg” test image from squoosh.app:
- Run
npx @squoosh/cli --mozjpeg "auto" "/path/to/photo.jpg"
(it doesn’t matter what format you use, as long as you encode it with"auto"
) - Observe that the process fails with the following message:
Worker error: Error [RuntimeError]: memory access out of bounds
at <anonymous>:wasm-function[69]:0x82f8
at <anonymous>:wasm-function[27]:0x29a3
at <anonymous>:wasm-function[71]:0xa1f5
at <anonymous>:wasm-function[116]:0xc600
at <anonymous>:wasm-function[115]:0xc4f5
at VisDiff$distance [as distance] (eval at Kb (/[...]/@squoosh/cli/build/index.js:1:1), <anonymous>:9:10)
at /[...]/@squoosh/cli/build/index.js:7:519788
at async binarySearch (/[...]/@squoosh/cli/build/index.js:7:519087)
at async autoOptimize (/[...]/@squoosh/cli/build/index.js:7:519585)
Expected behavior Expected the process to complete without errors.
Version:
- OS w/ version: Like Ubuntu 20.10
- Node version: 14.16.1, 15.14.0 (12.22.1 also fails, but error message is botched)
- npm version: 6.4.12, 7.10.0
Additional context, screenshots, screencasts I understand that at some point, the image becomes so large that you can’t expect Squoosh to work properly, but I think it is reasonable to expect that a relatively normal 4K photo can be encoded on a modern machine with above-average specs.
Issue Analytics
- State:
- Created 2 years ago
- Reactions:2
- Comments:6 (3 by maintainers)
Top GitHub Comments
Maybe this might help with debugging: I recompiled the visdif module with
-g2
and-s ASSERTIONS=1
and got this stack trace:Edit: I investigated that error above (misaligned block of memory) and it appears it might be due to some compiler bug. When I recompiled with
-O0
, the assertion error disappeared, and I was left with:Just tested with CLI v0.7.1. The error persists, although I just see a
bus error
. I’ll have to investigate deeper into Butteraugli.