Images imfilter performance drops when using ImageView

Hi,
imfilter exibit a huge variable performance drop when used in conjonction with ImageView.
Here is the test code:

using Images # ImageView

function test_imfilter()
	gk = Kernel.gaussian(2.0f0)
	I = rand(Float32,1000,2000)
	
	for i = 1:9
		start = time()
		J = imfilter(I,gk)
		t = round(time() - start, digits=6)
		println("$i imfilter $t sec")
	end
end

And the case, see that once ImageView is in use the performance drops

julia> include("test_imfilter.jl")
test_imfilter (generic function with 1 method)

julia> test_imfilter()
1 imfilter 0.357333 sec
2 imfilter 0.102812 sec
3 imfilter 0.02313 sec
4 imfilter 0.022202 sec
5 imfilter 0.023004 sec
6 imfilter 0.022911 sec
7 imfilter 0.022197 sec
8 imfilter 0.022959 sec
9 imfilter 0.022229 sec

julia> using ImageView
Gtk-Message: 07:11:13.124: Failed to load module "canberra-gtk-module"
Gtk-Message: 07:11:13.125: Failed to load module "canberra-gtk-module"

julia> test_imfilter()
1 imfilter 5.025525 sec
2 imfilter 0.027089 sec
3 imfilter 5.06874 sec
4 imfilter 2.871562 sec
5 imfilter 2.081181 sec
6 imfilter 0.118777 sec
7 imfilter 0.234288 sec
8 imfilter 5.030625 sec
9 imfilter 5.030824 sec

and strange enough

julia> @benchmark imfilter($I,$gk)
BenchmarkTools.Trial: 
  memory estimate:  223.13 KiB
  allocs estimate:  146
  --------------
  minimum time:     428.595 μs (0.00% GC)
  median time:      465.805 μs (0.00% GC)
  mean time:        218.079 ms (0.00% GC)
  maximum time:     5.006 s (0.00% GC)
  --------------
  samples:          23
  evals/sample:     1

Thanks, I can confirm this.

The profile is quite amusing. The tall stuff on the left is the actual filtering operation, but I have no idea what’s going on at the bottom. It just says in: -1

Might be worth using C=true when inspecting the profile. Might be best to move this to imfilter huge perf drop when · Issue #161 · JuliaImages/ImageFiltering.jl · GitHub.