JuliaImages / ImageFiltering.jl

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

Less alloc in TriggsSdika filtering (fix #243) #244

Closed timholy closed 2 years ago

timholy commented 2 years ago

Putting the string interpolation behind a @noinline is the key change, but it doesn't hurt to hoist the range creation.

Of the few remaining allocations, about half will be fixed by https://github.com/JuliaLang/julia/pull/43990, as they are another instance of https://github.com/JuliaLang/julia/issues/35972

timholy commented 2 years ago

CC @IanButterworth

codecov[bot] commented 2 years ago

Codecov Report

Merging #244 (41faa86) into master (424523c) will increase coverage by 0.00%. The diff coverage is 100.00%.

Impacted file tree graph

@@           Coverage Diff           @@
##           master     #244   +/-   ##
=======================================
  Coverage   91.86%   91.87%           
=======================================
  Files          12       12           
  Lines        1647     1649    +2     
=======================================
+ Hits         1513     1515    +2     
  Misses        134      134           
Impacted Files Coverage Δ
src/imfilter.jl 91.38% <100.00%> (+0.02%) :arrow_up:

Continue to review full report at Codecov.

Legend - Click here to learn more Δ = absolute <relative> (impact), ø = not affected, ? = missing data Powered by Codecov. Last update 424523c...41faa86. Read the comment docs.

IanButterworth commented 2 years ago

Many thanks! Though I thought this would have a bigger effect

julia> @btime imfilter!(img2, img1, kern, "symmetric");
  19.865 ms (30 allocations: 7.69 MiB)

master

julia> @btime imfilter!(img2, img1, kern, "symmetric");
  20.384 ms (1031 allocations: 7.77 MiB)

Also, I don't quite understand why the key change here makes a difference.. if that if branch isn't hit, were the interpolations still done when inlined??!

timholy commented 2 years ago

It somehow triggers retention and propagation of a gcframe. I don't really understand the details, unfortunately.