-
Notifications
You must be signed in to change notification settings - Fork 14
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
slow write performance for abstract array #76
Comments
That's a wild performance drop. My best guess is that there's an inference failure? |
This seems to be version related
The ReinterpretArray performance might be due to JuliaLang/julia#43287, which was fixed in Julia 1.8. This also causes ImageMagick's performance drop for JPEG JuliaIO/ImageMagick.jl#208 |
Thanks for thoroughly checking this. Glad to hear that this was fixed upstream. Can I go ahead and close? |
Given that eagerly collecting the data into contiguous memory takes less than 1ms in the same machine, I think there's more room for optimization to further close the gap. julia> @btime collect(reinterpret(Gray{Float64}, $img));
251.000 μs (2 allocations: 2.00 MiB) |
Writing to disk will almost always have orders of magnitude of slowdown. I'm sure there's performance to be had though. |
I mean, if |
That's fair. |
I ran into this performance slowdown again today, it appears to be especially egregious when using memory-mapped OMETIFFs and leads to ~100x slowdown versus writing the image lazily to disk frame-by-frame. |
After looking into this more, I think this is mostly a base Julia problem (correct me if I'm wrong here 😅), but even using Base casejulia> img = Float64.(testimage("cameraman"));
julia> @btime write("tmp.tiff", img)
287.581 μs (13 allocations: 728 bytes)
2097152 Gray typejulia> b = reinterpret(Gray{Float64}, img);
julia> @btime write("tmp.tiff", b)
ERROR: MethodError: no method matching write(::IOStream, ::Gray{Float64})
Closest candidates are:
write(::IO, ::Any) at io.jl:672
write(::IO, ::Any, ::Any...) at io.jl:673
write(::TiffFile, ::Any) at ~/.julia/packages/TiffImages/FEcMg/src/files.jl:117
...
Stacktrace:
[1] write(io::IOStream, x::Gray{Float64})
@ Base ./io.jl:672
julia> @btime write("tmp.tiff", reinterpret(UInt8, b)) # need to reinterpret
31.452 ms (14 allocations: 776 bytes)
2097152 Now, I'm forced to do the extra reinterpret because of issue highlighted here: JuliaLang/julia#24234 (comment) and it seems that reinterpret arrays are slow at writing: JuliaLang/julia#39781 Now interestingly if you reinterpret back to a Float64 instead of UInt8, it's faster julia> @btime write("tmp.tiff", reinterpret(Float64, b))
286.599 μs (13 allocations: 728 bytes)
2097152 But that doesn't generalize well: julia> img = RGB{Float64}.(testimage("cameraman")); # RGB colors this time
julia> @btime write("tmp.tiff", img) # takes about three times longer as expected
878.243 μs (13 allocations: 728 bytes)
6291456
julia> @btime write("tmp.tiff", reinterpret(Float64, img)) # now this is slow again
21.970 ms (786446 allocations: 12.00 MiB)
6291456
|
Fixed by JuliaLang/julia#42593? |
The text was updated successfully, but these errors were encountered: