Stream: helpdesk (published)

Topic: Slow image load


view this post on Zulip Yakir Luc Gagnon (Dec 15 2021 at 09:08):

I've recently noticed a significant slow down in loading images. This is hard to MWE because it depends on the image and the machine in question, but does this sound right to you:

(tmp) pkg> status
      Status `~/tmp/Project.toml`
  [5789e2e9] FileIO v1.11.2
  [6218d12a] ImageMagick v1.2.2

julia> versioninfo()
Julia Version 1.7.0
Commit 3bf9d17731 (2021-11-30 12:12 UTC)
Platform Info:
  OS: Linux (x86_64-linux-gnu)
  CPU: AMD Ryzen Threadripper 2950X 16-Core Processor
  WORD_SIZE: 64
  LIBM: libopenlibm
  LLVM: libLLVM-12.0.1 (ORCJIT, znver1)

julia> img = load(file);

julia> size(img)
(1440, 2560)

julia> filesize(file)
636254

julia> @btime load(file);
  1.307 s (44236893 allocations: 1.51 GiB)

Should a 1440x2560 pixels 600 KB image take 1.3 seconds to load?

view this post on Zulip Andrey Oskin (Dec 15 2021 at 09:16):

It doesn't sound right

view this post on Zulip Andrey Oskin (Dec 15 2021 at 09:17):

What is file here?

view this post on Zulip Andrey Oskin (Dec 15 2021 at 09:18):

Some IO object?

view this post on Zulip Yakir Luc Gagnon (Dec 15 2021 at 09:23):

No, file is just the string of the path to the image file (a jpg). I can upload an image so we all use the same exact file, but it's arbitrary, I get this kind of performance no matter what image file I use.

view this post on Zulip Sukera (Dec 15 2021 at 09:56):

where is the image loaded from? is it on an NFS?

view this post on Zulip Yakir Luc Gagnon (Dec 15 2021 at 12:05):

No no, it's just an image file on my hard-disk (HDD).

I've built a MWE to clarify my previous example:

using FileIO, Colors
img = rand(RGB, 1440, 2560)
file = "img.jpg"
save(file, img)

using BenchmarkTools
filesize(file) # 6422686 bytes
@btime load(file); #  1.478 s (44236892 allocations: 1.51 GiB)

view this post on Zulip Jakob Nybo Nissen (Dec 15 2021 at 13:57):

That takes at most 200 ms on my laptop

view this post on Zulip Yakir Luc Gagnon (Dec 15 2021 at 14:54):

So strange: I tried using ProfileView like this:

using ProfileView
using FileIO

file = "img.jpg"
function profile_test(n)
  for _ in 1:n
    load(file)
  end
end

@profview profile_test(1)

but it just stalled, got stuck, forever, which is weird in and of itself...

But this:

using ProfileView
using FileIO

file = "img.jpg"
load(file);

@profview load(file)

resulted in
screenshot_2021-12-15_154550.jpg

where the long green bar is wait in task.jl.

I have attached the jlprof file as well, if you want to take a look with:

julia> using ProfileView

julia> ProfileView.view(nothing)

and then press the load button and choose the attached
load_image.jlprof.

view this post on Zulip Jakob Nybo Nissen (Dec 15 2021 at 15:55):

Is it possible that it's spending all the time waiting for the underlying JPEG library, which perhaps uses a slow fallback on your system?

view this post on Zulip Jakob Nybo Nissen (Dec 15 2021 at 15:56):

Perhaps try reinstalling ImageMagick or whatever backend your FileIO uses for JPEG

view this post on Zulip Yakir Luc Gagnon (Dec 15 2021 at 21:07):

I mean, whenever I try to load an (specifically jpg) image I get:

ArgumentError: Package ImageMagick [6218d12a-5da1-5696-b52f-db25d2ecc6d1] is required but does not seem to be installed:
 - Run `Pkg.instantiate()` to install all recorded dependencies.

So I add ImageMagick, that's why the environment I have in my MWE includes ImageMagick:

(tmp) pkg> st
      Status `~/tmp/Project.toml`
  [5ae59095] Colors v0.12.8
  [5789e2e9] FileIO v1.11.2
  [6218d12a] ImageMagick v1.2.2

which is the latest version. So I'm not sure what else I could be doing?

view this post on Zulip Yakir Luc Gagnon (Dec 15 2021 at 21:13):

I just tested my MWE on my home laptop, and .. I got the same slow down!

julia> @btime load(file);
  3.459 s (44236892 allocations: 1.51 GiB)

What is going on...?!

view this post on Zulip Jakob Nybo Nissen (Dec 16 2021 at 05:47):

Not sure - I used a different MacOS only backend to check

view this post on Zulip Yakir Luc Gagnon (Dec 16 2021 at 06:35):

I'll open an issue...

view this post on Zulip Gerhard Aigner (Dec 16 2021 at 07:37):

I reproduced it on 1.7 - it doesn't happen on 1.6...

view this post on Zulip Gerhard Aigner (Dec 16 2021 at 07:39):

It has already been reported:
https://github.com/JuliaIO/ImageMagick.jl/issues/208


Last updated: Oct 02 2023 at 04:34 UTC