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?
It doesn't sound right
What is file
here?
Some IO
object?
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.
where is the image loaded from? is it on an NFS?
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)
That takes at most 200 ms on my laptop
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.
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?
Perhaps try reinstalling ImageMagick or whatever backend your FileIO uses for JPEG
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?
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...?!
Not sure - I used a different MacOS only backend to check
I'll open an issue...
I reproduced it on 1.7 - it doesn't happen on 1.6...
It has already been reported:
https://github.com/JuliaIO/ImageMagick.jl/issues/208
Awesome @Gerhard Aigner, I added my experience to that issue as well.
Yakir Luc Gagnon has marked this topic as resolved.
Last updated: Nov 22 2024 at 04:41 UTC