question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

[LIB/CLI] Butteraugli uses too much memory

See original GitHub issue

First 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: billede
  • 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:open
  • Created 2 years ago
  • Reactions:2
  • Comments:6 (3 by maintainers)

github_iconTop GitHub Comments

2reactions
jcao219commented, Jun 30, 2021

Maybe this might help with debugging: I recompiled the visdif module with -g2 and -s ASSERTIONS=1 and got this stack trace:

RuntimeError: abort(Assertion failed: reinterpret_cast<uintptr_t>(aligned) % kCacheLineSize == 0, at: node_modules/butteraugli/butteraugli/butteraugli.cc,82,Free) at Error
    at jsStackTrace (C:\Users\jcao2\dev\squoosh\libsquoosh\build\index.js:26:31265)
    at stackTrace (C:\Users\jcao2\dev\squoosh\libsquoosh\build\index.js:26:31441)
    at abort (C:\Users\jcao2\dev\squoosh\libsquoosh\build\index.js:26:25898)
    at ___assert_fail (C:\Users\jcao2\dev\squoosh\libsquoosh\build\index.js:26:31599)
    at butteraugli::CacheAligned::Free(void*) (<anonymous>:wasm-function[42]:0x46bf)
    at butteraugli::Blur(butteraugli::Image<float> const&, float, float) (<anonymous>:wasm-function[49]:0x57fa)
    at butteraugli::OpsinDynamicsImage(std::__2::vector<butteraugli::Image<float>, std::__2::allocator<butteraugli::Image<float> > > const&) (<anonymous>:wasm-function[51]:0x5adc)
    at butteraugli::ButteraugliDiffmap(std::__2::vector<butteraugli::Image<float>, std::__2::allocator<butteraugli::Image<float> > > const&, std::__2::vector<butteraugli::Image<float>, std::__2::allocator<butteraugli::Image<float> > > const&, double, butteraugli::Image<float>&) (<anonymous>:wasm-function[41]:0x1b7f)
    at VisDiff::distance(std::__2::basic_string<char, std::__2::char_traits<char>, std::__2::allocator<char> >) (<anonymous>:wasm-function[37]:0xddd)
    at emscripten::internal::MethodInvoker<double (VisDiff::*)(std::__2::basic_string<char, std::__2::char_traits<char>, std::__2::allocator<char> >), double, VisDiff*, std::__2::basic_string<char, std::__2::char_traits<char>, std::__2::allocator<char> > >::invoke(double (VisDiff::* const&)(std::__2::basic_string<char, std::__2::char_traits<char>, std::__2::allocator<char> >), VisDiff*, emscripten::internal::BindingType<std::__2::basic_string<char, std::__2::char_traits<char>, std::__2::allocator<char> >, void>::'unnamed'*) (<anonymous>:wasm-function[38]:0x1012)
    at abort (C:\Users\jcao2\dev\squoosh\libsquoosh\build\index.js:26:25929)
    at ___assert_fail (C:\Users\jcao2\dev\squoosh\libsquoosh\build\index.js:26:31599)
    at butteraugli::CacheAligned::Free(void*) (<anonymous>:wasm-function[42]:0x46bf)
    at butteraugli::Blur(butteraugli::Image<float> const&, float, float) (<anonymous>:wasm-function[49]:0x57fa)
    at butteraugli::OpsinDynamicsImage(std::__2::vector<butteraugli::Image<float>, std::__2::allocator<butteraugli::Image<float> > > const&) (<anonymous>:wasm-function[51]:0x5adc)
    at butteraugli::ButteraugliDiffmap(std::__2::vector<butteraugli::Image<float>, std::__2::allocator<butteraugli::Image<float> > > const&, std::__2::vector<butteraugli::Image<float>, std::__2::allocator<butteraugli::Image<float> > > const&, double, butteraugli::Image<float>&) (<anonymous>:wasm-function[41]:0x1b7f)
    at VisDiff::distance(std::__2::basic_string<char, std::__2::char_traits<char>, std::__2::allocator<char> >) (<anonymous>:wasm-function[37]:0xddd)
    at emscripten::internal::MethodInvoker<double (VisDiff::*)(std::__2::basic_string<char, std::__2::char_traits<char>, std::__2::allocator<char> >), double, VisDiff*, std::__2::basic_string<char, std::__2::char_traits<char>, std::__2::allocator<char> > >::invoke(double (VisDiff::* const&)(std::__2::basic_string<char, std::__2::char_traits<char>, std::__2::allocator<char> >), VisDiff*, emscripten::internal::BindingType<std::__2::basic_string<char, std::__2::char_traits<char>, std::__2::allocator<char> >, void>::'unnamed'*) (<anonymous>:wasm-function[38]:0x1012)
    at VisDiff$distance [as distance] (eval at new_ (C:\Users\jcao2\dev\squoosh\libsquoosh\build\index.js:26:56942), <anonymous>:9:10)
    at C:\Users\jcao2\dev\squoosh\libsquoosh\build\index.js:34:175

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:

RuntimeError: memory access out of bounds
    at free (<anonymous>:wasm-function[673]:0x130e7)
    at operator delete(void*) (<anonymous>:wasm-function[60]:0x1547)
    at void std::__2::__libcpp_operator_delete<void*>(void*) (<anonymous>:wasm-function[126]:0x268c)
    at void std::__2::__do_deallocate_handle_size<>(void*, unsigned long) (<anonymous>:wasm-function[124]:0x263f)
    at std::__2::__libcpp_deallocate(void*, unsigned long, unsigned long) (<anonymous>:wasm-function[121]:0x25c2)
    at std::__2::allocator<float>::deallocate(float*, unsigned long) (<anonymous>:wasm-function[272]:0x5073)
    at std::__2::allocator_traits<std::__2::allocator<float> >::deallocate(std::__2::allocator<float>&, float*, unsigned long) (<anonymous>:wasm-function[268]:0x4f6c)
    at std::__2::__vector_base<float, std::__2::allocator<float> >::~__vector_base() (<anonymous>:wasm-function[260]:0x4df0)
    at std::__2::vector<float, std::__2::allocator<float> >::~vector() (<anonymous>:wasm-function[253]:0x4a27)
    at butteraugli::Convolution(butteraugli::Image<float> const&, std::__2::vector<float, std::__2::allocator<float> > const&, float) (<anonymous>:wasm-function[307]:0x5c01)
1reaction
surmacommented, Jun 16, 2021

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.

Read more comments on GitHub >

github_iconTop Results From Across the Web

butteraugli estimates the psychovisual difference ... - GitHub
Introduction. Butteraugli is a project that estimates the psychovisual similarity of two images. It gives a score for the images that is reliable...
Read more >
Lintian Reports by Individual or Team - Debian
You can use the setting Rules-Requires-Root: no in the source stanza of debian/control , but please verify with diffoscope(1) that the installation packages ......
Read more >
https://packages.ubuntu.com/source/focal/all/allpa...
... (0.3.3+dfsg-3) [universe] alot (0.9-1) [universe] alpine (2.22+dfsg1-1) ... butt (0.1.18-1build1) [universe] butteraugli (0~20170116-3build1) [universe] ...
Read more >
Compare Packages Between Distributions - DistroWatch.com
This can let us know which distribution is more up to date, or if a feature has been ... butteraugli 0~20170116-3 ... endless-sky-high-dpi...
Read more >
pkg_w_new_homepage_field.txt
... allelecount all-knowing-dns alltray allure almanah alot alot-doc alpine ... busybox busybox-static busybox-syslogd butt butteraugli buzztrax bwa bwbasic ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found