# Images imfilter performance drops when using ImageView

**URL:** <https://discourse.julialang.org/t/images-imfilter-performance-drops-when-using-imageview/36630>\
**Category:** Performance\
**Created:** [March 28, 2020, 6:17am UTC](https://discourse.julialang.org/t/images-imfilter-performance-drops-when-using-imageview/36630 "2020-03-28T06:17:12Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![wizebt](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/wizebt/32/12256_2.png) [@wizebt](https://discourse.julialang.org/u/wizebt)\
**Post date:** [March 28, 2020, 6:17am UTC](https://discourse.julialang.org/t/images-imfilter-performance-drops-when-using-imageview/36630/1 "2020-03-28T06:17:12Z")

</div>

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

```julia
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
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
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

```

---

<div class="post-metadata">

**Author:** ![rsrock](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/rsrock/32/115_2.png) [@rsrock](https://discourse.julialang.org/u/rsrock)\
**Post date:** [March 30, 2020, 10:28pm UTC](https://discourse.julialang.org/t/images-imfilter-performance-drops-when-using-imageview/36630/2 "2020-03-30T22:28:06Z")

</div>

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`

 ![imfilter_profile.svg](https://global.discourse-cdn.com/julialang/original/3X/a/6/a6c806d88e23048756a75c0e48504e54affd7563.png)

---

<div class="post-metadata">

**Author:** ![tim.holy](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tim.holy/32/52_2.png) [@tim.holy](https://discourse.julialang.org/u/tim.holy)\
**Post date:** [March 31, 2020, 10:35am UTC](https://discourse.julialang.org/t/images-imfilter-performance-drops-when-using-imageview/36630/3 "2020-03-31T10:35:03Z")

</div>

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](https://github.com/JuliaImages/ImageFiltering.jl/issues/161).
