JuliaImages / ImageFiltering.jl

Julia implementations of multidimensional array convolution and nonlinear stencil operations
Other
99 stars 51 forks source link

`imfilter!` allocates significantly #243

Closed IanButterworth closed 2 years ago

IanButterworth commented 2 years ago

I believe this setup, with imfilter! and symmetric should be allocation-free/minimal?

Below uses the new allocation profiler in julia 1.8

julia> img1 = rand(Float32, 1000, 1000);

julia> img2 = similar(img1);

julia> kern = KernelFactors.IIRGaussian((2.0,2.0));

julia> @time imfilter!(img2, img1, kern, "symmetric");
  1.017254 seconds (2.70 M allocations: 144.354 MiB, 3.17% gc time, 97.60% compilation time)

julia> @time imfilter!(img2, img1, kern, "symmetric");
  0.017806 seconds (1.03 k allocations: 7.768 MiB)

julia> using Profile, PProf

julia> Profile.Allocs.@profile sample_rate=0.5 imfilter!(img2, img1, KernelFactors.IIRGaussian((2.0,2.0)), "symmetric");

julia> PProf.Allocs.pprof(from_c = false)

Screenshot from 2022-02-06 22-49-56

cc. @johnnychen94

timholy commented 2 years ago

Not sure what's going on here. One small point, you get substantially better performance with kern = KernelFactors.IIRGaussian(Float32, (2.0,2.0)); (the images are Float32 so...)