Skip to content

Julia 1.7 performance regression on JPEG image #208

@johnnychen94

Description

@johnnychen94

CRef: JuliaImages/Images.jl#992

The following patch fixes the performance issue, but I'm lost in the memory orders...

diff --git a/src/ImageMagick.jl b/src/ImageMagick.jl
index db26f64..b0c36fb 100755
--- a/src/ImageMagick.jl
+++ b/src/ImageMagick.jl
@@ -149,13 +149,14 @@ function load_(file::Union{AbstractString,IO,Vector{UInt8}}, permute_horizontal=
     sz, T, cs, channelorder = _metadata(wand)
 
     # Allocate the buffer and get the pixel data
-    buf = Array{T}(undef, sz)
-    exportimagepixels!(rawview(channelview(buf)), wand, cs, channelorder)
+    buf = Array{UInt8}(undef, (length(T), sz...))
+    exportimagepixels!(buf, wand, cs, channelorder)
 
     orient = getimageproperty(wand, "exif:Orientation", false)
     default = (A,ph) -> ph ? vertical_major(A) : identity(A)
     oriented_buf = get(orientation_dict, orient, default)(buf, permute_horizontal)
-    view ? oriented_buf : collect(oriented_buf)
+    colorful_buf = length(T) == 1 ? reinterpret(T, reshape(buf, sz)) : reinterpretc(T, buf)
+    view ? colorful_buf : collect(colorful_buf)
 end

cc: @etibarg

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions